Is there an equivalent of Scala's Either in Java 8?

后端 未结 8 793
南旧
南旧 2020-11-28 23:00

Just like java.util.Optional in Java 8 is (somewhat) equivalent to Scala\'s Option[T] type, is there an equivalent to Scala\'s Eithe

8条回答
  •  天命终不由人
    2020-11-28 23:53

    No, there is none.

    Java language developers explicitly state that types like Option are intended to be used only as temporary values (e.g. in stream operations results), so while they are the same thing as in other languages, they are not supposed to be used as they are used in other languages. So it is not surprising that there is no such thing as Either because it does not arise naturally (e.g. from stream operations) like Optional does.

提交回复
热议问题