Getting the languages from Language class

隐身守侯 提交于 2019-12-11 10:37:29

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!