I have such code:
public class GenClass<T>
{
public static void m()
{
//I need to know here, what is T ?
}
}
class Test
{
class Cl1 extends GenClass<Integer>{}
class Cl2 extends GenClass<MyClass>{}
class Cl3 extends GenClass<Cl3>{}
public static void main(String[] args)
{
Cl1.m();
Cl2.m();
Cl3.m();
}
}
How can I know inside method m
, what is T
?
PS: I'm very new to java (my language is C#). I've found such construction as a solution of similar problem:
return (Class) ((ParameterizedType) /*getClass()*/GenClass.class
.getGenericSuperclass()).getActualTypeArguments()[0];
But it was about instance method, so as I can't call getClass()
from static method, I've tried to replace it by GenClass.class
, but looks like .class
eveluates statically, so it probably have not any info about T
.