Check if a field is final in java using reflection
The best and only one way is: Modifier.isFinal(f.getModifiers())
Reference:
Field.getModifiers
Modifier.isFinal
You can use getModifiers()
method on the Field
variable:
if ((f.getModifiers() & Modifier.FINAL) == Modifier.FINAL)
{
//this is final field
}