Uses for Optional

前端 未结 14 1435
眼角桃花
眼角桃花 2020-11-22 01:01

Having been using Java 8 now for 6+ months or so, I\'m pretty happy with the new API changes. One area I\'m still not confident in is when to use Optional. I se

14条回答
  •  难免孤独
    2020-11-22 01:31

    Seems Optional is only useful if the type T in Optional is a primitive type like int, long, char, etc. For "real" classes, it does not make sense to me as you can use a null value anyway.

    I think it was taken from here (or from another similar language concept).

    Nullable

    In C# this Nullable was introduced long ago to wrap value types.

提交回复
热议问题