Hi is there any way in Java to get staticly generic class type
I have ended up with construct
List l = new ArrayList&
Since all List
classes actually correspond to the same class at runtime, you could do this:
Class> c
= (Class>) List.class;
But for some reason, Java doesn't like it. Tried it with String:
Laj.java:9: inconvertible types
found : java.lang.Class
required: java.lang.Class>
Class> c = (Class>) List.class;
Well, let's fool it then:
Class> c =
(Class>) (Class>) List.class;
It's silly, but it works. It produces an "unchecked" warning, but so does your example. Note that it doesn't result in the same class as your example, though. Your example returns the actual class of the object, namely ArrayList
. This one returns List
, obviously.