Class TryVoid


  • public class TryVoid
    extends Object

    An instance of this class represents either a “success” or a “failure”, in which case it encapsulates a cause of type Throwable.

    Instances of this class are immutable.

    • Method Detail

      • run

        public static TryVoid run​(Throwing.Runnable<Throwable> runnable)
        Attempts to run the given runnable, and returns a success if it succeeds; or a failure encapsulating the exception thrown by the runnable if it threw one.
        Returns:
        a success iff the given runnable did not throw an exception.
      • success

        public static TryVoid success()
        Returns a success.
      • failure

        public static TryVoid failure​(Throwable cause)
        Returns a failure encapsulating the given cause.
      • isSuccess

        public boolean isSuccess()
        Returns true iff this object represents a success.
        Returns:
        true iff isFailure() returns false
      • isFailure

        public boolean isFailure()
        Returns true iff this object represents a failure; equivalently, iff it encapsulates a cause.
        Returns:
        true iff isSuccess() returns false
      • equals

        public boolean equals​(Object o2)
        Returns true iff the given object is a Try and, either: this object and the given object are both successes; or this object and the given object are both failures and they encapsulate equal causes.
        Overrides:
        equals in class Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • toString

        public String toString()
        Returns a string representation of this object, suitable for debug.
        Overrides:
        toString in class Object