Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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.

like image 292
Alexander Mills Avatar asked Aug 26 '13 03:08

Alexander Mills


People also ask

What are transient fields in Java?

Transient in Java is used to indicate that a field should not be part of the serialization process. The modifier Transient can be applied to member variables of a class to turn off serialization on these member variables. Every field that is marked as transient will not be serialized.

Which is a field modifier?

There are several modifiers that may be part of a field declaration: Access modifiers: public , protected , and private. Field-specific modifiers governing runtime behavior: transient and volatile. Modifier restricting to one instance: static.

What is the reflection in Java?

Reflection is a feature in the Java programming language. It allows an executing Java program to examine or "introspect" upon itself, and manipulate internal properties of the program. For example, it's possible for a Java class to obtain the names of all its members and display them.


1 Answers

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

like image 139
Keith Avatar answered Sep 19 '22 05:09

Keith