how do I find out if a Java field has the transient modifier?
Asked Answered
G

1

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.

Greywacke answered 26/8, 2013 at 3:37 Comment(0)
S
59
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

Saadi answered 26/8, 2013 at 3:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.