George Cherry said:
Why is this an advantage? Doesn't it break
the polymorphism contract?
Polymorphism: an object of a given class can
have multiple forms, either its own class or
any class it extends. If a class does not honor
all the contract of its superclass, doesn't it break
polymorphism?
Yes, it breaks polymorphism, but in the case of marker interfaces
without methods you don't have much polymorphism anyway. Actually, in
the serialization framework of a project I'm involved in
(jcore.dev.java.net) we've been pondering the different aspects of
marker interfaces and annotations with regard to marking a class as
serializable. We decided on using an annotation that is not inherited
to sub classes, as this will force developers to explicitly mark their
classes as serializable and thus think about the serialization issue.
Serializing instances of classes not marked as serializable will cause
a runtime exception. We feel that this better than automatically
inheriting the serializable attribute from the super class, and
possibly do incorrect serialization of the class instances
(serializing fields that should be transient, incorrect versioning
etc.).
/JN