Class Const<T>

java.lang.Object
io.jenetics.prog.op.Val<T>
io.jenetics.prog.op.Const<T>
All Implemented Interfaces:
Op<T>, Serializable, Function<T[],T>, Supplier<Op<T>>

public final class Const<T> extends Val<T> implements Serializable
Represents an operation which always returns the same, constant, value. To improve readability, constants may have a name. If a name is given, this name is used when printing the program tree. The Const operation is a terminal operation.
final static Op<Double> PI = Const.of("π", Math.PI); final static Op<Double> ONE = Const.of(1.0);
Since:
3.9
Version:
7.0
See Also:
  • Method Details

    • value

      public T value()
      Description copied from class: Val
      Return the constant value.
      Specified by:
      value in class Val<T>
      Returns:
      the constant value
    • toString

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

      public static <T> Const<T> of(String name, T value)
      Return a new constant with the given name and value.
      Type Parameters:
      T - the constant type
      Parameters:
      name - the constant name
      value - the constant value
      Returns:
      a new constant
      Throws:
      NullPointerException - if the given constant name is null
    • of

      public static <T> Const<T> of(T value)
      Return a new constant with the given value.
      Type Parameters:
      T - the constant type
      Parameters:
      value - the constant value
      Returns:
      a new constant