Package io.grpc

Class StatusOr<T>

java.lang.Object
io.grpc.StatusOr<T>

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

    • fromValue Link icon

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

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

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

      @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 Link icon

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

      public boolean equals(Object other)
      Note that StatusOr containing statuses, the equality comparision is delegated to Status.equals(java.lang.Object) which just does a reference equality check because equality on Statuses is not well defined. Instead, do comparison based on their Code with Status.getCode(). The description and cause of the Status are unlikely to be stable, and additional fields may be added to Status in the future.
      Overrides:
      equals in class Object
    • hashCode Link icon

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

      public String toString()
      Overrides:
      toString in class Object