Null check in Java 8 Elvis operator?

早过忘川 提交于 2019-11-28 03:08:45

问题


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?

I have read that

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

I know Java 8 allows this

String name = computer.flatMap(Computer::getSoundcard)
                          .flatMap(Soundcard::getUSB)
                          .map(USB::getVersion)
                          .orElse("UNKNOWN");

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.

Edit: By Elvis operator I mean this:

String version = computer?.getSoundcard()?.getUSB()?.getVersion();

or similar


回答1:


No. There are no current or future plans to reconsider the null-safe operators in Java.



来源:https://stackoverflow.com/questions/26529091/null-check-in-java-8-elvis-operator

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!