Serializing private variables in java

前端 未结 4 2157
一生所求
一生所求 2021-02-19 16:38

I have a question on serialization. If my class has private variables and there are no getters and setters, then how will the value of these variables be read by the Serializat

4条回答
  •  名媛妹妹
    2021-02-19 17:12

    The default serialization mechanism doesn't care about the access scope of member variables. In other words public, protected, package-private, and private variables are all treated in the same way. The implementation details might vary, but as I remember the Sun JRE does this by implementing much of the serialization in native (JNI) code where access privileges aren't enforced.

提交回复
热议问题