将不强制转换的接口变量与 java 中的枚举值进行比较
Comparing interface variable without cast to Enum value in java
是否有说明或文档说明此比较有效?
static void sout(final Interface i) {
if(i == Enum.TWO) {
...
}
}
...
public enum Enum implements Interface{
ONE, TWO, THREE
}
那么为什么不需要转换或 instanceof
需要?
谢谢@AndyTurner!这就是我要找的。
不需要 instanceof 或显式转换:
It is a compile-time error if it is impossible to convert the type of either operand to the type of the other...
在 运行 时,这是一个普通的对象相等。
是否有说明或文档说明此比较有效?
static void sout(final Interface i) {
if(i == Enum.TWO) {
...
}
}
...
public enum Enum implements Interface{
ONE, TWO, THREE
}
那么为什么不需要转换或 instanceof
需要?
谢谢@AndyTurner!这就是我要找的。
不需要 instanceof 或显式转换:
It is a compile-time error if it is impossible to convert the type of either operand to the type of the other...
在 运行 时,这是一个普通的对象相等。