This code does not work:
public static <T> void doSomething(Class clazz) { List<clazz> list = new ArrayList<>(); } How can I put a generic type variable?
This is usually done like this:
public static <T> void doSomething(Class<T> clazz) { List<T> list = new ArrayList<>(); } You can also pass not a class, but a representative:
public static <T> void doSomething(T t) List<T> list = new ArrayList<>(); } You can create an object of the desired class using reflection .
Source: https://ru.stackoverflow.com/questions/741116/
All Articles
List<Class> list? - Alexey Shimansky