33

At Spring's @Cacheable annotation I want to specify an unless condition.

However my return value is neither a primitive type nor a Java bean, but an Enum.

How can I compare for equality with another Enum in SpEL (Spring Expression Language)?

Harold L. Brown
  • 8,423
  • 11
  • 57
  • 109

2 Answers2

81
#result == T(fully.qualified.path.to.AnEnum).A_VALUE

Reference here:

You can use the special T operator to specify an instance of java.lang.Class (the type).

jumping_monkey
  • 5,941
  • 2
  • 43
  • 58
Harold L. Brown
  • 8,423
  • 11
  • 57
  • 109
28

#object.someEnumProperty.name() == 'CERTAIN_VALUE'

would work as well.

sorrymissjackson
  • 2,395
  • 1
  • 19
  • 18