Find the class of the generic object
Posted
by
Mgccl
on Stack Overflow
See other posts from Stack Overflow
or by Mgccl
Published on 2011-01-09T23:33:32Z
Indexed on
2011/01/09
23:53 UTC
Read the original article
Hit count: 193
java
|type-erasure
Suppose I have the following class.
public class gen<T> {
public gen(){
}
Class<T> class(){
//something that figures out what T is.
}
}
How can I implement the class() function without pass any additional information?
What I did is here, but I have to pass a object of T into the object gen.
public class gen<T> {
public gen(){
}
Class<T> class(T var){
return (Class<T>) var.getClass();
}
}
© Stack Overflow or respective owner