Y
Hacker News
new
|
ask
|
show
|
jobs
by
accountLost
1903 days ago
You can't easily create a instance of the generic type in java. for example :
return new T();
is possible in C#, not in java.
1 comments
ohgodplsno
1903 days ago
There is a way-ish, which is passing a Class<T> as an additional parameter and doing clazz.newInstance().
Definitely not pleasant though.
link
Felk
1903 days ago
For that particular use case it may be better to pass a constructor reference / new instance supplier to not rely on reflection.
link
Definitely not pleasant though.