这是代码:
public class Main {
public static void main(String[] args) {
Gen<Integer> g = new Gen<Integer>(5);
System.out.println(g.getClass());
System.out.println(g.ob.getClass());
}
}
class Gen<T> {
T ob;
public Gen(T x) {
ob = x;
}
}
Run Code Online (Sandbox Code Playgroud)
这是输出
class Gen // This I understand
class java.lang.Integer // But if type erasure is happening, shouldn't this be java.lang.Object?
Run Code Online (Sandbox Code Playgroud)
我知道Type参数T
在运行时被擦除了,但是为什么ob
在运行时存活的类型参数呢?
有没有办法像这样传递注释参数:
@MyAnnotation(4)
代替
@MyAnnotation( value = 4)