Class Try.Success<T>

java.lang.Object
io.vavr.control.Try.Success<T>
Type Parameters:
T - the type of the contained value
All Implemented Interfaces:
Try<T>, Value<T>, Serializable, Iterable<T>
Enclosing interface:
Try<T>

public static final class Try.Success<T> extends Object implements Try<T>, Serializable
Represents a successful Try containing a value.

Instances of this class indicate that the computation completed successfully and hold the resulting value of type T.


 Try<Integer> success = new Try.Success<>(42);
 success.isSuccess(); // true
 success.get();       // 42
 
Author:
Daniel Dietrich
See Also:
  • Method Details

    • get

      public T get()
      Description copied from interface: Try
      Returns the value of this Try if it is a Try.Success, or throws the underlying exception if it is a Try.Failure.

      Important: If this Try is a Try.Failure, the exception thrown is exactly the Try.getCause() of this Failure. The underlying cause is thrown sneakily (without being declared in the method signature).

      Specified by:
      get in interface Try<T>
      Specified by:
      get in interface Value<T>
      Returns:
      the value contained in this Success
    • getCause

      public Throwable getCause()
      Description copied from interface: Try
      Returns the cause of failure if this Try is a Try.Failure.
      Specified by:
      getCause in interface Try<T>
      Returns:
      the throwable cause of this Try.Failure
    • isEmpty

      public boolean isEmpty()
      Description copied from interface: Try
      Checks whether this Try contains no value, i.e., it is a Try.Failure.
      Specified by:
      isEmpty in interface Try<T>
      Specified by:
      isEmpty in interface Value<T>
      Returns:
      true if this is a Try.Failure, false if this is a Try.Success
    • isFailure

      public boolean isFailure()
      Description copied from interface: Try
      Checks whether this Try is a Try.Failure.
      Specified by:
      isFailure in interface Try<T>
      Returns:
      true if this is a Try.Failure, false if this is a Try.Success
    • isSuccess

      public boolean isSuccess()
      Description copied from interface: Try
      Checks whether this Try is a Try.Success.
      Specified by:
      isSuccess in interface Try<T>
      Returns:
      true if this is a Try.Success, false if this is a Try.Failure
    • 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 Try<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 Try<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 Try<T>
      Specified by:
      toString in interface Value<T>
      Overrides:
      toString in class Object
      Returns:
      A String representation of this object