Class Property<T>

  • Type Parameters:
    T - type of the property.

    public final class Property<T>
    extends Object
    Holds a (not-nullable) property value and provides an event when the value is changed.
    Author:
    Leonid Bushuev from JetBrains
    • Constructor Detail

      • Property

        public Property​(@NotNull
                        T initialValue)
        Initializes the property with the given value.
        Parameters:
        initialValue - the initial value.
    • Method Detail

      • set

        public void set​(@NotNull
                        T newValue)
        Assigns the new value to this property and fires notifications if the value is really changed.

        This method uses the equals function of the value to check whether the value differs.

        Parameters:
        newValue - the new value.
      • get

        @NotNull
        public T get()
        Returns the property value.
        Returns:
        the property value.
      • attachListener

        public void attachListener​(@NotNull
                                   Property.Listener<T> listener)
        Attaches the given listener.
        Parameters:
        listener - the listener to attach.
      • detachListener

        public void detachListener​(@NotNull
                                   Property.Listener<T> listener)
        Detaches the given listener.

        If the listener already was detached or was never attached - does nothing silently.

        Parameters:
        listener - the listener to detach.