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

后端 未结 8 723
南旧
南旧 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:52

    There is no Either in the Java Standard Library. However there is an implementation of Either in FunctionalJava, along with many other nice classes.

    0 讨论(0)
  • 2020-11-28 23:53

    No, there is none.

    Java language developers explicitly state that types like Option<T> 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.

    0 讨论(0)
提交回复
热议问题