Record Class LiteralNode
java.lang.Object
java.lang.Record
cloud.opencode.base.expression.ast.LiteralNode
- Record Components:
value- the literal value | 字面量值
- All Implemented Interfaces:
Node
Literal Node
字面量节点
Represents literal values: numbers, strings, booleans, null.
表示字面量值:数字、字符串、布尔值、null。
Features | 主要功能:
- Typed factory methods for int, long, double, string, boolean, null - 为int、long、double、string、boolean、null提供类型化工厂方法
- Constant folding optimization support - 支持常量折叠优化
Usage Examples | 使用示例:
Node num = LiteralNode.ofInt(42);
Node str = LiteralNode.ofString("hello");
Node nil = LiteralNode.ofNull();
Object result = num.evaluate(ctx); // 42
Security | 安全性:
- Thread-safe: Yes, immutable record - 线程安全: 是,不可变记录
- Null-safe: Yes, null value is a valid literal - 空值安全: 是,null值是合法字面量
- Since:
- JDK 25, opencode-base-expression V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionLiteralNode(Object value) Creates an instance of aLiteralNoderecord class. -
Method Summary
Modifier and TypeMethodDescriptionfinal booleanIndicates whether some other object is "equal to" this one.evaluate(EvaluationContext context) Evaluate this node 求值此节点final inthashCode()Returns a hash code value for this object.static LiteralNodeCreate literal node with any value 创建任意值的字面量节点static LiteralNodeofBoolean(boolean value) Create boolean literal 创建布尔字面量static LiteralNodeofDouble(double value) Create double literal 创建双精度字面量static LiteralNodeofInt(int value) Create integer literal 创建整数字面量static LiteralNodeofLong(long value) Create long literal 创建长整数字面量static LiteralNodeofNull()Create null literal 创建 null 字面量static LiteralNodeCreate string literal 创建字符串字面量Get string representation for debugging 获取用于调试的字符串表示final StringtoString()Returns a string representation of this record class.value()Returns the value of thevaluerecord component.Methods inherited from interface Node
getTypeName
-
Constructor Details
-
LiteralNode
-
-
Method Details
-
of
Create literal node with any value 创建任意值的字面量节点- Parameters:
value- the literal value | 字面量值- Returns:
- the literal node | 字面量节点
-
ofNull
Create null literal 创建 null 字面量- Returns:
- the null literal node | null 字面量节点
-
ofBoolean
Create boolean literal 创建布尔字面量- Parameters:
value- the boolean value | 布尔值- Returns:
- the boolean literal node | 布尔字面量节点
-
ofInt
Create integer literal 创建整数字面量- Parameters:
value- the integer value | 整数值- Returns:
- the integer literal node | 整数字面量节点
-
ofLong
Create long literal 创建长整数字面量- Parameters:
value- the long value | 长整数值- Returns:
- the long literal node | 长整数字面量节点
-
ofDouble
Create double literal 创建双精度字面量- Parameters:
value- the double value | 双精度值- Returns:
- the double literal node | 双精度字面量节点
-
ofString
Create string literal 创建字符串字面量- Parameters:
value- the string value | 字符串值- Returns:
- the string literal node | 字符串字面量节点
-
evaluate
Description copied from interface:NodeEvaluate this node 求值此节点 -
toExpressionString
Description copied from interface:NodeGet string representation for debugging 获取用于调试的字符串表示- Specified by:
toExpressionStringin interfaceNode- Returns:
- the string representation | 字符串表示
-
toString
-
hashCode
-
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared withObjects::equals(Object,Object). -
value
-