Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<blockquote> <p>If the class represents a model object that may be transferred across the n/w, it should be serializable. Is this reasoning correct?</p> </blockquote> <p>This reasoning is somewhat correct. If you are creating a public API where compatibility will be important, you may wish to make classes serializable which <i>might</i> one day need to be serialized. However, if you are creating a private application, classes should be made serializable only when needed. One reason (among a few) to attempt to avoid implementing <code>Serializable</code> is that it introduces the need to maintain and secure the newly added 'interface' to your serializable class: its byte-code representation. </p> <blockquote> <p>If so, what is the logic behind some of native Java API classes being serializable while others are not? From this list of native classes that implement Serilizable, it appears that there is more than one reason to implement serializable.</p> </blockquote> <p>One of the main reasons why many classes in the Java API do not implement <code>Serializable</code> is that, due to the nature of interfaces and inheritence, any class which extends a class which implements <code>Serializable</code> must also implement <code>Serializable</code>. For example, if <a href="https://stackoverflow.com/questions/11600213/why-doesnt-java-lang-object-implement-the-serializable-interface"><code>java.lang.Object</code> implemented <code>Serializable</code></a>, every java class would need to be designed to be properly serializable. This would place a large burden on the design of any class: suddenly, security and byte-code validity and compatibility would need to be considered.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload