What is the need to implement Serializable interface (with
no methods) for objects which are to be serialized ?
We can write our own functionality which writes objects to
streams then why we need to implement and tell JVM that
which objects can be serialized.
Answer Posted / akj504
Ya that answers are expected but...
If we open ObjectOutputStream.java (which is used for
serialization) then we see the following code :
............................
writeObject0(Object obj, boolean unshared){
.............
} else if (cl.isArray()) {
writeArray(obj, desc, unshared);
} else if (obj instanceof Serializable) {
writeOrdinaryObject(obj, desc, unshared);
} else {
throw new NotSerializableException(cl.getName());
}
................
If we remove the checking instanceof (& recompile) or if we
override the writeObject0 method then
Will it still check whethere the class has implemented
serilizable ?
| Is This Answer Correct ? | 1 Yes | 1 No |
Post New Answer View All Answers
Is minecraft 1.15 out?
What do you mean by default constructor in java?
What are selection structures?
What is jvm? How its run?
What is the relationship between clipping and repainting under awt?
What one should take care of, while serializing the object?
What differences exist between iterator and listiterator?
Explain what do you mean by functional overloading in java?
What is the size of arraylist in java?
What is the relationship difference the canvas class and the graphics class?
What is var keyword ?
Write a function to find out longest palindrome in a given string?
How to optimize the javac output?
Discuss about garbage collector in Java.
Why synchronization is important?