Can a transient
field in a class be obtained using reflection? (using getDeclaredField(..)
)
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
transient
fields have nothing to do with reflection. The keyword only signals that a field should be skipped during Java serialization process. So reflection can accesstransient
fields just like any other fields.transient
indicates that the field will not be serialized. The field is still declared by the class, so it is fair game for reflection.Yes, It is a normal field. You can check whether it is transient by:
So no logical reason for it not to be accessible by reflection. It's the value of the field that is ignored (sometimes), not the field itself.
(btw, what hindered you from just trying to call
getDeclaredField("yourTransientField")
?)Among all the objects that needs to be serialized there are those one that need not to be serialized. That's why this objects are marked with the keyword transient.