Question about introduction of Either/Result like type to the Java language

mfejzer mfejzer at mat.umk.pl
Sun Feb 22 20:45:05 UTC 2026


Hello,

I’d like to ask what you think about the introduction of an 
Either/Result-like type like type to the Java language?

Some attempts to write functional-like code in Java encounter no 
standard implementation of Either/Result-like type. Such type is usually 
used for explicit failure handling without exception usage, and is 
present in some other languages. Lack of such type in Java causes 
creation of many ad-hoc implementations which behave slightly 
differently.
Examples:
* 
https://github.com/vavr-io/vavr/blob/main/vavr/src/main/java/io/vavr/control/Either.java
* 
https://github.com/functionaljava/functionaljava/blob/series/5.x/core/src/main/java/fj/data/Either.java
* 
https://github.com/aol/cyclops/blob/master/cyclops/src/main/java/cyclops/control/Either.java
* 
https://github.com/resilience4j/resilience4j/blob/master/resilience4j-core/src/main/java/io/github/resilience4j/core/functions/Either.java
* 
https://github.com/kusoroadeolu/ferrous/blob/main/src/main/java/io/github/kusoroadeolu/ferrous/result/Result.java
Introducing this type to the Java language would provide a standard 
implementation, allowing its use without depending on third-party 
libraries.

Sketch, based on example from ferrous library:
- java.util.Result<F,S>, sealed interface permitting Success and Failure 
records,
- records: Success<F,S>(S successValue), Failure<F,S>(F failureValue),
- available methods: success/failure factories; 
map/flatMap/mapFailure/flatMapFailure; fold; peek/peekFailure; 
consume/ConsumeFailure etc.

Non-goals:
- Replacing exceptions
- Extending language syntax
- Introducing additional functional programming concepts (Monads, Optics 
etc)

Kind regards,
Mikołaj Fejzer


More information about the amber-dev mailing list