Java 8 Elvis运算符中的空检查? [英] Null check in Java 8 Elvis operator?
问题描述
问题:是否有针对任何未来Java版本安排的 Elvis运算符的实现?或者是否有任何图书馆将其带入Java?
Question: Is there an implementation of the Elvis operator scheduled for any future Java release? Or is there any Library that brings it to Java?
我已阅读
<它是针对Java SE 7提出的,但没有进入该版本
it was proposed for Java SE 7 but didn't make it into that release
http://www.oracle.com/technetwork/articles/java/java8-optional-2175753.html
我知道Java 8允许这个
I know Java 8 allows this
String name = computer.flatMap(Computer::getSoundcard)
.flatMap(Soundcard::getUSB)
.map(USB::getVersion)
.orElse("UNKNOWN");
但我觉得这有点太多了。因此,如果有人能指出任何将Groovy喜欢/ C#类似语法的项目/库用于Null Checks的Java,我将不胜感激。
but I it's s bit too much for my taste. SO if anyone could point me out any project / library that would bring the Groovy like/C# like syntax to Java for Null Checks, would be greatly appreciated.
编辑:通过Elvis运算符我的意思是:
By Elvis operator I mean this:
String version = computer?.getSoundcard()?.getUSB()?.getVersion();
或类似的
推荐答案
没有。目前或将来没有计划重新考虑Java中的空值安全运算符。
No. There are no current or future plans to reconsider the null-safe operators in Java.
这篇关于Java 8 Elvis运算符中的空检查?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!