A plug-in that tells expressions how to create an object for
new Name(...).
Usually not needed: a StandardEvaluationContext already runs the
constructors registered on a SpelType (through
SpelTypeConstructorResolver), so registering the type is enough.
Implement this interface to create objects of types that are not
registered, and add it with
StandardEvaluationContext.addConstructorResolver. A
SimpleEvaluationContext has no constructor resolvers, so new
always fails there.
// Creates points without registering a Point type.
final class PointResolver implements ConstructorResolver {
@override
ConstructorExecutor? resolve(EvaluationContext context,
String typeName, List<Object?> arguments) =>
typeName == 'Point' && arguments.length == 2
? (_, args) => Point(args[0]! as int, args[1]! as int)
: null;
}
final context = StandardEvaluationContext()
..addConstructorResolver(PointResolver());
SpelExpressionParser().parseExpression('new Point(1, 2)')
.getValue(context);
Spring (Java):
context.addConstructorResolver(new PointResolver());
parser.parseExpression("new Point(1, 2)").getValue(context);
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
resolve(
EvaluationContext context, String typeName, List< Object?> arguments) → ConstructorExecutor? -
An executor that creates a
typeName(the name as written afternew, dots included) fromarguments, ornullto let the next resolver try. When no resolver matches, the call fails withconstructorNotFound(EL1002E). -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited