且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Java中的instanceof - 为什么不编译?

更新时间:2023-11-05 16:42:40

根据JLS§15.20.2


如果将 RelationalExpression 转换为 ReferenceType 作为编译时错误被拒绝,那么 instanceof 关系ex压力同样产生编译时错误。在这种情况下, instanceof 表达式的结果永远不会为真。

If a cast of the RelationalExpression to the ReferenceType would be rejected as a compile-time error, then the instanceof relational expression likewise produces a compile-time error. In such a situation, the result of the instanceof expression could never be true.

RelationalExpression instanceof 的第一个操作数, ReferenceType 是第二个。

RelationalExpression is the first operand of instanceof and ReferenceType is the second.