Serializable & Cloneable
Hi all,
I am new to java. When I looked into the API, I found that both Serializable and Cloneable interfaces don't have any methods.
My question is: Shouldn't both of them be a keyword(just like abstract, final, synchronized, etc.) instead of a dummy interface? What is the need for going for an interface in this kind of scenario?
--Palani
Message was edited by:
Palani@java
# 4
Imagine you have some code which deals with Serializable objects. You can do this by simply coding against the type Serializable, that is, have methods which have Serializable in their signature somewhere, that sort of thing. Now imagine that there is no Serializable interface, but instead the proposed serializable keyword. The language would then need to provide a mechanism for checking if something was serializable, similar to the instanceof operator, perhaps. There the language has bloated to the tune of 2 new keywords, and more syntax to be learnt. That's just to replace one marker interface.
And of course, you wouldn't be able to extend the language to include your own defined marker interfaces. The use of the Serializable interface was a neat-ish solution. If the feature was introduced now, I wouldn't be surprised if it manifested itself as an annotation