29

In the Java reflection world -

how do we find out if a Field object has the transient modifier?

http://docs.oracle.com/javase/tutorial/reflect/member/fieldModifiers.html

the documentation is not helping.

Filip
  • 3,002
  • 1
  • 26
  • 37
Alexander Mills
  • 90,741
  • 139
  • 482
  • 817

1 Answers1

58
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;

Field field = YourClass.class.getField("fieldName");
boolean isTransient = Modifier.isTransient(field.getModifiers());

For more details see Class Modifier

Filip
  • 3,002
  • 1
  • 26
  • 37
Keith
  • 4,144
  • 1
  • 19
  • 14