How to get a static enumeration from a class

I have a java-constraint-interface declaring some enums.

public interface MyClass{static enum BOOP{a,b,c,d,e,f}};

How can I dynamically get the name of the 6th enum-const from "BOOP" -enum?

${org.java.some.MyClass."$enumName"[5]}

doenst work.

+3
source share
2 answers

I got it myself

<%=org.java.some.MyClass.class.getDeclaredClasses().find{it.simpleName=enumName}.values()[5]%>
+1
source

This should work:

public interface MyClass{static enum BOOP{a,b,c,d,e,f}};

${org.java.some.MyClass.BOOP.values()[5]}    // prints f

Also, you cannot get an element with index 6 because the array is based on 0, and you don't have 7 elements in your enumeration.

+1
source

All Articles