Question

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.

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top