类 Result<T>

  • 类型参数:
    T - the value type

    public class Result<T>
    extends java.lang.Object
    A Result hold a non-null value, or a exception if error occurred.
    • 方法概要

      所有方法 静态方法 实例方法 具体方法 
      修饰符和类型 方法 说明
      boolean equals​(java.lang.Object o)  
      java.lang.Throwable error()
      Get the error of failed Result.
      boolean failed()
      Return if Result is failed.
      static <T> Result<T> failed​(java.lang.Throwable e)
      Create a failed Result with an error.
      T get()
      Get the value of Result.
      T getOrElse​(T fallback)
      Get the value of Result, or return the fallback value if Result is failed.
      int hashCode()  
      static <T> Result<T> of​(T value)
      Create a Result with a value.
      boolean succeeded()
      Return if Result is succeeded.
      java.util.Optional<T> toOptional()
      Convert Result to Optional, discard the error Exception.
      java.lang.String toString()  
      • 从类继承的方法 java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • 方法详细资料

      • of

        public static <T> Result<T> of​(T value)
        Create a Result with a value.
      • failed

        public static <T> Result<T> failed​(java.lang.Throwable e)
        Create a failed Result with an error.
      • succeeded

        public boolean succeeded()
        Return if Result is succeeded.
      • failed

        public boolean failed()
        Return if Result is failed.
      • get

        public T get()
        Get the value of Result.
        抛出:
        java.lang.IllegalStateException - If Result is failed
      • getOrElse

        public T getOrElse​(T fallback)
        Get the value of Result, or return the fallback value if Result is failed.
      • error

        public java.lang.Throwable error()
        Get the error of failed Result.
        抛出:
        java.lang.IllegalStateException - If Result is not failed
      • toOptional

        public java.util.Optional<T> toOptional()
        Convert Result to Optional, discard the error Exception.
        返回:
        An Optional contains the value, or empty Optional if is a failed Result.
      • equals

        public boolean equals​(java.lang.Object o)
        覆盖:
        equals 在类中 java.lang.Object
      • hashCode

        public int hashCode()
        覆盖:
        hashCode 在类中 java.lang.Object
      • toString

        public java.lang.String toString()
        覆盖:
        toString 在类中 java.lang.Object