Here's a simplified method I have to implement:
class Sample<T> {
Class<List<T>> getType() {
}
}
So the solution to it could be:
class Sample<T> {
final Class<List<T>> type;
Sample(Class<List<T>> type) {
this.type = type;
}
Class<List<T>> getType() {
return type;
}
static void test() {
@SuppressWarnings("unchecked")
Class<List<Integer>> clazz = (Class<List<Integer>>) (Class<?>) List.class;
Sample<Integer> sample = new Sample<>(clazz);
}
}
Is there a way to avoid the warning when instantiating clazz?
Or even better - to avoid passing it in constructor and just get the desired result based on the class type?
Thanks!
>`.
– Radiodef Jun 07 '18 at 02:22