Java conditional operator ?: result type

后端 未结 5 1264
忘了有多久
忘了有多久 2020-11-27 17:38

I\'m a bit puzzled about the conditional operator. Consider the following two lines:

Float f1 = false? 1.0f: null;
Float f2 = false? 1.0f: false? 1.0f: null;         


        
5条回答
  •  时光取名叫无心
    2020-11-27 18:00

    To be or not to be, that is the question. :)

    Edit: Actually, looking closer it seems that this case is actually a mix between the Hamlet (ternary operator and wrapped integral types) and the Elvis (auto-unboxing null) puzzlers. In any case, I can only recommend watching the video, it is very educational and enjoyable.

提交回复
热议问题