问题
I am trying to access a bunch of final static public ints from a class using reflection. This class however doesn't have a constructor - e.g. the android R.id . I am trying to get all int values for these, however I can't seem to access it due to the fact that you can't create the class. I was thinking of possible extending it just to create a constructor, but I am unsure this is wise. Any suggestions? I can't modify R.id or R.array (at least I shouldn't I think).
Thanks in advanced! Jon
回答1:
That's all you need:
Field field = R.id.class.getField("some_var");
int value = field.getInt(null);
回答2:
This should help you.
来源:https://stackoverflow.com/questions/5406108/reflectively-accessing-final-static-variable-without-initialization