19 Ağustos 2019 Pazartesi

Externalizable Arayüzü

Giriş
Açıklaması şöyle. Yani nesnemizin default constructor metoduna sahip olması gerekir.
1. When an Externizable object is reconstructed, an object is created using public no-arg constructor before the readExternal method is called. If a public no-arg constructor is not present, then a InvalidClassException is thrown at runtime.
2. Using Externalizable, we can even serialize/deserialize transient variables, so declaring fields transient becomes unnecessary.
3. Using Externalizable, we can even serialize/deserialize static variables if we need to.
Bu arayüz Serializable arayüzünden kalıtır. Açıklaması şöyle.
The Externalizable interface is a child interface of Serializable i.e. Externalizable extends Serializable. So if we implement Externalizable interface and override its writeExternal() and readExternal() methods, then our first preference is given to these methods over the default serialization mechanism provided by the JVM. These methods supersede customized implementations of writeObject and readObject methods. So if we also provide writeObject() and readObject(), then they will be ignored.
Yani bu arayüzden kalıtınca writeExternal() ve readExternal() metodları override edilir. Bazıları readObject() ve writeObject() metodlarını da boş olacak şekilde kodluyor.

Hiç yorum yok:

Yorum Gönder