Module jakarta.data

Interface Literal<V>

Type Parameters:
V - entity attribute type.
All Superinterfaces:
Expression<Object,V>
All Known Subinterfaces:
BooleanLiteral, ComparableLiteral<V>, NumericLiteral<N>, StringLiteral, TemporalLiteral<V>

public interface Literal<V> extends Expression<Object,V>

Literal represents an immutable value within an Expression. Literals are created implicitly when obtaining expressions that involve literal values.

The entity and static metamodel for the code examples within this class are shown in the Attribute Javadoc.

Since:
1.1
  • Method Details

    • value

      V value()

      Returns the value represented by this Literal. The value will never be null.

      Returns:
      the value.
    • of

      static <V> Literal<V> of(V value)

      Creates a Literal or subtype of Literal that represents the given value.

      The most specific subtype of Literal, such as NumericLiteral, StringLiteral, TemporalLiteral, or ComparableLiteral, should be used instead wherever possible.

      Type Parameters:
      V - entity attribute type.
      Parameters:
      value - an immutable value or a mutable value that must never be modified after it is supplied to this method. Must never be null.
      Returns:
      a Literal representing the value.
      Throws:
      NullPointerException - if the value is null.
    • toString

      String toString()

      Returns a String representing the literal value.

      Subtypes of Literal override this method to define more specific formats that more closely align with query language.

      This method outputs a String that begins with an opening curly brace and ends with a closing curly brace. Between the braces are 3 terms delimited by a space character. The first term is Literal. The second term is the fully qualified class name of the value's type. The third term is the toString() output of the value, enclosed in single quotes.

      For example, the output of Literal.of(ZoneId.of("America/Chicago")).toString() is

       {Literal java.time.ZoneId 'America/Chicago'}
       
      Overrides:
      toString in class Object
      Returns:
      a String representing the literal value.