Java enumeration list in class [copy]

See English answers > java enums: List enumerated values from a class 4

Namely

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

I can't find a way to get the values () method

Solution

Class #getenumconstants() returns enumeration constants (type safe)

So,

public static <T extends Enum> List<T> getList(Class<T> clazz) {
    return Arrays.asList(clazz.getEnumConstants());
}
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>