I have a small problem in java while using genericity. I have a class A
:
public class A<T>
In a method of A
, I need to get the type name of T
.
Is there a way to find the string s
using T
?
(If I create A<String> temp = new A<String>();
, I want to be able to get java.lang.String
at one point - I have to use genericity because one of my methods will have to return a List<T>
).
This seems quite easy but I do not see how to do it.
If you're doing it in a subclass which has it's parent class defining the generic type, this is what worked for me:
Reason why I couldn't do it with
#getClass()
instead of#toString()
in the first snip is that I was always getting the "Class" class, which is useless to me.