L - The left type.R - The right type.public abstract class Either<L,R> extends Object
Either type (an explicit sum type for Java).| Modifier and Type | Class and Description |
|---|---|
static class |
Either.Left<L,R>
The
Left type. |
static class |
Either.Right<L,R>
The
Right type. |
| Modifier and Type | Method and Description |
|---|---|
L |
getLeft()
Returns the left value (if this is a left value).
|
R |
getRight()
Returns the right value (if this is a right value).
|
boolean |
isLeft()
Checks whether this
Either is a left value. |
boolean |
isRight()
Checks whether this
Either is a right value. |
static <L,R> Either<L,R> |
left(L value)
Creates a left value.
|
static <L,R> Either<L,R> |
left(L value,
Class<R> rightType)
Creates a left value.
|
static <L,R> Either<L,R> |
right(R value)
Creates a right value.
|
static <L,R> Either<L,R> |
right(R value,
Class<L> leftType)
Creates a right value.
|
public static <L,R> Either<L,R> left(L value)
L - The left type.R - The right type.value - The value to encapsulate as left.public static <L,R> Either<L,R> left(L value, Class<R> rightType)
value - The value to encapsulate as left.rightType - The right type (to aid in type inference)public static <L,R> Either<L,R> right(R value)
L - The left type.R - The right type.value - The value to encapsulate as left.public static <L,R> Either<L,R> right(R value, Class<L> leftType)
value - The value to encapsulate as right.rightType - The right type (to aid in type inference)public boolean isLeft()
Either is a left value.public boolean isRight()
Either is a right value.public L getLeft()
UnsupportedOperationException - if this is not actually a Either.Left.public R getRight()
UnsupportedOperationException - if this is not actually a Either.Right.Copyright © 2015. All rights reserved.