Class DefaultComputable<T>

java.lang.Object
com.guinetik.corefun.DefaultComputable<T>
Type Parameters:
T - the type of the value
All Implemented Interfaces:
Computable<T>

public class DefaultComputable<T> extends Object implements Computable<T>
Default immutable implementation of Computable.

DefaultComputable provides a simple, thread-safe implementation of the Computable interface. The wrapped value is stored as a final field, ensuring immutability.

Thread Safety

This class is immutable and therefore thread-safe. The wrapped value itself should also be immutable or thread-safe for the container to be fully thread-safe.

Usage

Typically, you should use Computable.of(Object) rather than constructing this class directly:


 Computable<String> comp = Computable.of("value");  // Preferred
 Computable<String> comp2 = new DefaultComputable<>("value");  // Also valid
 
Since:
0.1.0
Author:
Guinetik <guinetik@gmail.com>
See Also:
  • Constructor Details

    • DefaultComputable

      public DefaultComputable(T value)
      Creates a new DefaultComputable with the given value.
      Parameters:
      value - the value to wrap
  • Method Details

    • getValue

      public T getValue()
      Description copied from interface: Computable
      Retrieves the value managed by this computable.
      Specified by:
      getValue in interface Computable<T>
      Returns:
      the current value
    • toString

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

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

      public int hashCode()
      Overrides:
      hashCode in class Object