Class Option.Some<T>

java.lang.Object
io.vavr.control.Option.Some<T>
Type Parameters:
T - The type of the optional value.
All Implemented Interfaces:
Option<T>, Value<T>, Serializable, Iterable<T>
Enclosing interface:
Option<T>

public static final class Option.Some<T> extends Object implements Option<T>, Serializable
Some represents a defined Option. It contains a value which may be null. However, to create an Option containing null, new Some(null) has to be called. In all other cases Option.of(Object) is sufficient.
See Also:
  • Field Details

    • serialVersionUID

      private static final long serialVersionUID
      See Also:
    • value

      private final T value
  • Constructor Details

    • Some

      private Some(T value)
      Creates a new Some containing the given value.
      Parameters:
      value - A value, may be null
  • Method Details

    • get

      public T get()
      Description copied from interface: Option
      Gets the value if this is a Some or throws if this is a None.
      Specified by:
      get in interface Option<T>
      Specified by:
      get in interface Value<T>
      Returns:
      the value
    • isEmpty

      public boolean isEmpty()
      Description copied from interface: Option
      Returns true, if this is None, otherwise false, if this is Some.
      Specified by:
      isEmpty in interface Option<T>
      Specified by:
      isEmpty in interface Value<T>
      Returns:
      true, if this Option is empty, false otherwise
    • equals

      public boolean equals(Object obj)
      Description copied from interface: Value
      Clarifies that values have a proper equals() method implemented.

      See Object.equals(Object).

      Specified by:
      equals in interface Option<T>
      Specified by:
      equals in interface Value<T>
      Overrides:
      equals in class Object
      Parameters:
      obj - An object
      Returns:
      true, if this equals o, false otherwise
    • hashCode

      public int hashCode()
      Description copied from interface: Value
      Clarifies that values have a proper hashCode() method implemented.

      See Object.hashCode().

      Specified by:
      hashCode in interface Option<T>
      Specified by:
      hashCode in interface Value<T>
      Overrides:
      hashCode in class Object
      Returns:
      The hashcode of this object
    • stringPrefix

      public String stringPrefix()
      Description copied from interface: Value
      Returns the name of this Value type, which is used by toString().
      Specified by:
      stringPrefix in interface Value<T>
      Returns:
      This type name.
    • toString

      public String toString()
      Description copied from interface: Value
      Clarifies that values have a proper toString() method implemented.

      See Object.toString().

      Specified by:
      toString in interface Option<T>
      Specified by:
      toString in interface Value<T>
      Overrides:
      toString in class Object
      Returns:
      A String representation of this object