Class Notification<T>

java.lang.Object
io.reactivex.rxjava3.core.Notification<T>
Type Parameters:
T - the value type

public final class Notification<T> extends Object
Represents the reactive signal types: onNext, onError and onComplete and holds their parameter values (a value, a Throwable, nothing).
  • Field Details

    • value

      final Object value
    • COMPLETE

      static final Notification<Object> COMPLETE
      The singleton instance for createOnComplete.
  • Constructor Details

    • Notification

      private Notification(@Nullable @Nullable Object value)
      Not meant to be implemented externally.
      Parameters:
      value - the value to carry around in the notification, not null
  • Method Details

    • isOnComplete

      public boolean isOnComplete()
      Returns true if this notification is an onComplete signal.
      Returns:
      true if this notification is an onComplete signal
    • isOnError

      public boolean isOnError()
      Returns true if this notification is an onError signal and getError() returns the contained Throwable.
      Returns:
      true if this notification is an onError signal
      See Also:
    • isOnNext

      public boolean isOnNext()
      Returns true if this notification is an onNext signal and getValue() returns the contained value.
      Returns:
      true if this notification is an onNext signal
      See Also:
    • getValue

      @Nullable public T getValue()
      Returns the contained value if this notification is an onNext signal, null otherwise.
      Returns:
      the value contained or null
      See Also:
    • getError

      @Nullable public @Nullable Throwable getError()
      Returns the container Throwable error if this notification is an onError signal, null otherwise.
      Returns:
      the Throwable error contained or null
      See Also:
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

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

      public String toString()
      Overrides:
      toString in class Object
    • createOnNext

      @NonNull public static <@NonNull T> @NonNull Notification<T> createOnNext(@NonNull T value)
      Constructs an onNext notification containing the given value.
      Type Parameters:
      T - the value type
      Parameters:
      value - the value to carry around in the notification, not null
      Returns:
      the new Notification instance
      Throws:
      NullPointerException - if value is null
    • createOnError

      @NonNull public static <T> @NonNull Notification<T> createOnError(@NonNull @NonNull Throwable error)
      Constructs an onError notification containing the error.
      Type Parameters:
      T - the value type
      Parameters:
      error - the error Throwable to carry around in the notification, not null
      Returns:
      the new Notification instance
      Throws:
      NullPointerException - if error is null
    • createOnComplete

      @NonNull public static <T> @NonNull Notification<T> createOnComplete()
      Returns the empty and stateless shared instance of a notification representing an onComplete signal.
      Type Parameters:
      T - the target value type
      Returns:
      the shared Notification instance representing an onComplete signal