Package 

Class Optional


  • 
    public class Optional<T>
    
                        

    Optional wrapper can be to pass nullable value safely through RxJava2 stream. Though Android supports this construct since API level 24, using it is not viable because the SDK has to support lower API levels.

    • Constructor Summary

      Constructors 
      Constructor Description
      Optional(T value) Constructs a new optional value
    • Method Summary

      Modifier and Type Method Description
      static <T> Optional<T> from(T value)
      boolean isPresent() Checks if a non-null value is present.
      T get() Gets the optional value if present.
      int hashCode()
      boolean equals(Object rhs)
      static <T> Optional<T> empty() Returns an empty Optional instance.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Optional

        Optional(T value)
        Constructs a new optional value
        Parameters:
        value - the optional value
    • Method Detail

      • isPresent

         boolean isPresent()

        Checks if a non-null value is present.

      • get

        @NonNull() T get()

        Gets the optional value if present.

      • empty

         static <T> Optional<T> empty()

        Returns an empty Optional instance. No value is present for this Optional.