Given a class containing an enum:
public class MyClass {
public enum NestedEnum {
value1(1),
value2(2);
private int code;
private NestedEnum(int code) {
this.code = code;
}
public int getCode() {
return code;
}
}
}
how do I reference NestedEnum? This:
#{T(MyClass.NestedEnum).value1.getCode()}
results in the exception:
org.springframework.expression.spel.SpelEvaluationException: EL1005E:(pos 0): Type cannot be found 'namespace.MyClass.NestedEnum'
This:
#{T(T(MyClass).NestedEnum).value1.getCode()}
results in the exception:
org.springframework.expression.spel.SpelParseException: EL1043E:(pos 3): Unexpected token. Expected 'rparen())' but was 'lparen(()'
I cannot think of any other good options to try.
The Spring Expression Language (SpEL for short) is a powerful expression language that supports querying and manipulating an object graph at runtime. The language syntax is similar to Unified EL but offers additional features, most notably method invocation and basic string templating functionality.
The following kinds of expression cannot be compiled at the moment: Expressions involving assignment. Expressions relying on the conversion service. Expressions using custom resolvers or accessors.
You have to separate the enum using a $
sign:
#{T(MyClass$NestedEnum).value1.getCode()}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With