Как ссылаться на вложенный тип в SpEL?

данный класс, содержащий перечисление:

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;
        }
    }
}

как я ссылку NestedEnum? Это:

#{T(MyClass.NestedEnum).value1.getCode()}

приводит к исключению:

org.springframework.expression.spel.SpelEvaluationException: EL1005E:(pos 0): Type cannot be found 'namespace.MyClass.NestedEnum'

Это:

#{T(T(MyClass).NestedEnum).value1.getCode()}

приводит к исключению:

org.springframework.expression.spel.SpelParseException: EL1043E:(pos 3): Unexpected token.  Expected 'rparen())' but was 'lparen(()'

Я не могу придумать никаких других хороших вариантов, чтобы попробовать.

1 ответов


вы должны отделить перечисление, используя $ вход:

#{T(MyClass$NestedEnum).value1.getCode()}