我怎样才能做到这一点?
public class GenericClass<T>
{
public Type getMyType()
{
//How do I return the type of T?
}
}
Run Code Online (Sandbox Code Playgroud)
到目前为止我尝试的所有东西总是返回类型Object
而不是使用的特定类型.
据我所知,泛型是Java的编译时功能,编译后的字节代码中不存在参数化类型信息.我现在发现了Field#getGenericType和Method#getGenericReturnType方法,从而打破了我的世界观.请帮我把它拼凑起来.