tags:

views:

85

answers:

1

How do I go from a Class object to a list of enums generically?

i.e.

public static <T extends Enum> List<T> getList(Class<T> clazz)

I cant find a way to get to the values() method

+10  A: 

Class#getEnumConstants() returns the enum constants (type-safe).

So,

public static <T extends Enum> List<T> getList(Class<T> clazz) {
    return Arrays.asList(clazz.getEnumConstants());
}
Bozho
Ha! I *knew* there was something nicer!
Joachim Sauer