[英]Reference Type Equality at compile time
I came across following statement in Java Language Specification-8.It states that 2 classes are same at compile time if:我在 Java Language Specification-8 中遇到了以下语句。它指出,如果满足以下条件,则 2 个类在编译时是相同的:
But why does compiler raises a duplicate class error for但是为什么编译器会引发重复的类错误
class Test<String>{
...
}
class Test<Integer>{
...
}
Here binary name is same but argument types are different.What am I missing here?这里的二进制名称相同但参数类型不同。我在这里缺少什么?
It is not the argument, but the Type
of a generic class.它不是参数,而是泛型类的
Type
。 This type information is removed at runtime, so from a JVM point of view it is identical.此类型信息在运行时被删除,因此从 JVM 的角度来看它是相同的。
You can read more about Generics
and Type Erasure
in the Oracle docs .您可以在Oracle 文档中阅读有关
Generics
和Type Erasure
更多信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.