问题
I use this Unofficial Java Google Translate API to translate a text from a language to another language.
I have Language
class that contains the all language names like in the image bellow:

I want to get an array with the languages names. How can I do this?
If it would be C# I would do this:
PropertyInfo[] languages;
languages = typeof(Language).GetProperties();
回答1:
You can get all the fields with
Field[] fields = Language.class.getDeclaredFields();
for(Field field: fields)
if (field.getType() == String.class)
System.out.println(field.getName() + " = " + field.get(null));
回答2:
Since Language
isn't an enum
in that library, you'll have to use reflection to find all the members.
来源:https://stackoverflow.com/questions/14243203/getting-the-languages-from-language-class