Package io.grpc

Class StatusOr<T>


  • @ExperimentalApi("https://github.com/grpc/grpc-java/issues/11563")
    public class StatusOr<T>
    extends java.lang.Object
    Either a Status or a value.
    • Field Detail

      • status

        private final Status status
      • value

        private final T value
    • Constructor Detail

      • StatusOr

        private StatusOr​(Status status,
                         T value)
    • Method Detail

      • fromValue

        public static <T> StatusOr<T> fromValue​(@Nullable
                                                T value)
        Construct from a value.
      • fromStatus

        public static <T> StatusOr<T> fromStatus​(Status status)
        Construct from a non-Ok status.
      • hasValue

        public boolean hasValue()
        Returns whether there is a value.
      • getValue

        @Nullable
        public T getValue()
        Returns the value if set or throws exception if there is no value set. This method is meant to be called after checking the return value of hasValue() first.
      • getStatus

        public Status getStatus()
        Returns the status. If there is a value (which can be null), returns OK.
      • equals

        public boolean equals​(java.lang.Object other)
        Overrides:
        equals in class java.lang.Object
      • hashCode

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

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object