Java class object from type variable
Posted
by Alexander Temerev
on Stack Overflow
See other posts from Stack Overflow
or by Alexander Temerev
Published on 2010-05-10T08:24:50Z
Indexed on
2010/05/10
8:34 UTC
Read the original article
Hit count: 328
Is there a way to get Class object from the type variable in Java generic class? Something like that:
public class Bar extends Foo<T> {
public Class getParameterClass() {
return T.class; // doesn't compile
}
}
This type information is available at compile time and therefore should not be affected by type erasure, so, theoretically, there should be a way to accomplish this. Does it exist?
© Stack Overflow or respective owner