[英]Usage of instanceof <pattern> in NetBeans 11.3 + OpenJDK 14
After OpenJDK update to 14, the instanceof
grammar was extended, so now we can use patterns: RelationalExpression instanceof Pattern
. OpenJDK 更新到 14 后,
instanceof
语法被扩展,所以现在我们可以使用模式: RelationalExpression instanceof Pattern
。 More info here .更多信息在这里。 In NetBeans 11.3 I noticed the hint
instanceof <pattern> can be used here
near this method:在 NetBeans 11.3 中,我注意到提示
instanceof <pattern> can be used here
此方法附近使用:
public String getTLSCipherSuite() {
if (socket instanceof SSLSocket) {
return ((SSLSocket) socket).getSession().getCipherSuite();
}
return null;
}
If I change reference type to pattern, I see NetBeans error:如果我将引用类型更改为模式,我会看到 NetBeans 错误:
public String getTLSCipherSuite() {
if (socket instanceof SSLSocket sslSocket) {//<--- ")" expected
return sslSocket.getSession().getCipherSuite();
}
return null;
}
Perhaps it's NetBeans bug?也许是 NetBeans 错误?
This JDK 14 feature can only be used if NetBeans 11.3 itself is running on Java 14 javac, not the nb-javac packaged with NetBeans 11.3.仅当 NetBeans 11.3 本身在 Java 14 javac 上运行,而不是与 NetBeans 一起打包的 nb-javac 时,才能使用此 JDK 14 功能。 The java compiler's --enable-preview flag must be set also.
java 编译器的 --enable-preview 标志也必须设置。 See https://netbeans.apache.org/download/nb113/index.html for details.
有关详细信息,请参阅https://netbeans.apache.org/download/nb113/index.html 。 Of course, running NetBeans on javac instead of nb-javac means losing the nb-javac advantages.
当然,在 javac 上运行 NetBeans 而不是 nb-javac 意味着失去了 nb-javac 的优势。 See the links in https://blogs.apache.org/netbeans/entry/what-s-nb-javac-in for a discussion of the trade-offs.
有关权衡的讨论,请参阅https://blogs.apache.org/netbeans/entry/what-s-nb-javac-in中的链接。 The instanceof syntax is still listed as a preview feature in JDK 15, so there is no guarantee it won't change in future Java versions.
instanceof 语法仍被列为 JDK 15 中的预览功能,因此不能保证在未来的 Java 版本中不会更改。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.