In short
If A and B are 2 class, the only problem is A.class
works but A<B>.class
doesn't.
In Detail
I am very new to Java and I am trying to apply .class property on a class like ArrayList<String>
. Please note there can be anything in place of ArrayList.
If I have a normal class like "public class Student", then I can simply write
Class<Student> classType = Student.class;
But if I have class like A<B>
, then I can't simply write
Class<ArrayList<Student>> classType = ArrayList<Student>.class;
this doesn't compile. How to get Class<ArrayList<Student>>
from ArrayList
I have tried doing
var classType = new ArrayList<Student>().getClass();
but here the type of classType is Class<? extends ArrayList>
But I want the type of classType as Class<ArrayList<Student>>
How to get that?