I am wondering what - if this is even possible - the method of determining the access level of a field (private/protected/public) in java.
What I want to do is find out if there is any protected fields in a class. This is the method I have so far in my base abstract class:
public boolean hasOptions() {
for (Field field : getClass().getDeclaredFields()) {
// Method to determine if field is protected.
return true;
}
return false;
}
I've looked around without being able to find an answer.
Thanks!
Yes, use the
static
utility methods of theModifier
class. For example