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

There is a way-ish, which is passing a Class<T> as an additional parameter and doing clazz.newInstance().

Definitely not pleasant though.

For that particular use case it may be better to pass a constructor reference / new instance supplier to not rely on reflection.