Java 8 Elvis 运算符中的空检查? [英] Null check in Java 8 Elvis operator?
问题描述
问题:Elvis 运算符 是否计划在未来的任何 Java 版本中实现?或者是否有任何库将其引入 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# 之类的语法引入 Java 以进行 Null 检查的项目/库,我将不胜感激.
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.
猫王接线员的意思是:
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屋!