java - Comparing interface variable without cast to Enum value in java
问题描述
Is there a specification or documentation why this comparison works?
static void sout(final Interface i) {
if(i == Enum.TWO) {
...
}
}
...
public enum Enum implements Interface{
ONE, TWO, THREE
}
So why is there no cast or instanceof
needed?
解决方案
Thank you @AndyTurner! This is what i was looking for.
There's no instanceof or explicit cast needed:
It is a compile-time error if it is impossible to convert the type of either operand to the type of the other...
At run-time this is a normal object equality equals.
推荐阅读
- php - Laravel GrapQL 文件下载
- python - 如何有效地从二元对话(即两方之间的一组替代话语)中提取三元组?
- chatbot - Amazon Lex 使用来自 Amazon Connect 的话语
- c++ - 没有尖括号的模板使用 - 重载?
- r - 关于如何在 R 闪亮的应用程序中创建词汇表的任何想法?
- arrays - 我们如何使用自定义值更新数组字段的值/在 mongodb 的嵌套数组中添加字段
- php - 规范 MaaS 的 PHP OAuth1 提供程序
- python - 是否可以在模型删除时执行功能?
- css - ViewEncapsulation.ShadowDom 和 Primeng。并非所有样式都呈现
- reactjs - 如何通过反应路线传递数据