I need to iterate over the list of static fields of a class (say MyClass ). These fields are of type java.util.regex.Pattern. Using reflection, I can get all the static fields as follows:
MyClass mc = new MyClass(); List<Pattern> patternList = new ArrayList<Pattern>(); for (Field f : Commands.class.getDeclaredFields()) { if (Modifier.isStatic(f.getModifiers())) {
Now, since I know that all f fields are of type java.util.regex.Pattern, I want to create a List<Pattern> containing all of them. How can i do this?
I did not find a single question that would fit me, although there are a few questions about the thoughts. I apologize if my question is repeated.
source share