iterate static int values in java

后端 未结 5 1250
感动是毒
感动是毒 2020-12-19 05:09

I have a simple question. Is there a way ( using reflections I suppose ) to iterate all the static values of a class?

For instance

class Any {
    s         


        
5条回答
  •  庸人自扰
    2020-12-19 05:42

    Your solution works for public fields but not private fields like you have in your example. If you want to be able to access the private fields of a class you need to use getDeclaredFields() instead of getFields().

提交回复
热议问题