public abstract class Union2<First,Second> extends Object implements Cloneable, Serializable
Object.equals(java.lang.Object)
and Object.hashCode()
treat this as a container,
not identical to the contained object, but the identity is based on the contained
object. The union is serialiable if its contained object is.
Object.toString()
delegates to the contained object.Modifier and Type | Method and Description |
---|---|
abstract Union2<First,Second> |
clone() |
static <First,Second> |
createFirst(First first)
Construct a union based on the first type.
|
static <First,Second> |
createSecond(Second second)
Construct a union based on the second type.
|
abstract First |
first()
Retrieve the union member of the first type.
|
abstract boolean |
hasFirst()
Check if the union contains the first type.
|
abstract boolean |
hasSecond()
Check if the union contains the second type.
|
abstract Second |
second()
Retrieve the union member of the second type.
|
public abstract First first() throws IllegalArgumentException
IllegalArgumentException
- if the union really contains the second typepublic abstract Second second() throws IllegalArgumentException
IllegalArgumentException
- if the union really contains the first typepublic abstract boolean hasFirst()
public abstract boolean hasSecond()
public static <First,Second> Union2<First,Second> createFirst(First first)
first
- an object of the first typepublic static <First,Second> Union2<First,Second> createSecond(Second second)
second
- an object of the second type