Java – how to find enumerations of class definitions?

I know that I can get public static members of a class in the following ways:

obj. getClass(). getFields()

But that didn't get me enumerated I want to be able to get them from the class object returned by the getClass method Any ideas?

Solution

(turn into a community wiki because it seems to have a considerable expansion, such as comments that include strong comments. When I have no meaning, just transcribe comments when everyone can expand it.)

Do you mean enumerations nested in top-level classes? If so, use class Getdeclaraedclasses () and iterate over the results to see if any nested classes are enumerations The easiest way to test each nested class is to use class isEnum(); If you want to traverse the values in the enumeration, class Getenumconstants () is the way to go

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
分享
二维码
< <上一篇
下一篇>>