2 ms·
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.
by accountLost 6y 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.
- ohgodplsno 6y agoThere is a way-ish, which is passing a Class<T> as an additional parameter and doing clazz.newInstance(). Definitely not pleasant though.
- Felk 6y agoFor that particular use case it may be better to pass a constructor reference / new instance supplier to not rely on reflection.