当前位置:优学网  >  在线题库

这是什么语法?myVariable=无效的myVariable:5

发表时间:2022-07-02 00:15:08 阅读:82

大家好,这个问题很简单.我只是不知道如何谷歌这个,我们使用这个在我们的框架,我想了解更多关于它,但我不知道它是什么.你能帮忙吗?这是最简单的例子.任何线索我怎么能谷歌它将是一个很好的回答我.

 myVariable != null ? myVariable : 5
🎖️ 优质答案
  • Ternary operator. If myVariable does not equal null, the expression evaluates to myVariable. Otherwise, 5*.

    Equivalent to:

    myVariable == null ? 5 : myVariable

    *Since myVariable is compared to null, this is clearly an object rather than a primitive, so the entire expression is expected to return an object, so technically this returns Integer.valueOf(5).

  • 相关问题