I have a generic class that has a method which needs to know the runtime type:
public class SomePOJO<TYPE> {
// ... lots of code
public void doSomething() {
// Obtain runtime type of TYPE and do something with it.
}
}
I tried following the most upvoted answer of this question, and implemented doSomething()
like so:
public void doSomething() {
// |<-- error starts here
Class clazz = (Class)((TYPE)getClass().getGenericSuperclass()).getActualTypeArguments()[0];
}
However this is throwing a compiler error:
The method getActualTypeArguments() is undefined for the type TYPE
I am compiling against JDK 1.6u34 - where am I going wrong - and why?