Re: abstract static methods (again)
Eric Sosman wrote:
Tomas Mikula wrote:
On Tue, 20 Oct 2009 12:12:31 -0700, Daniel Pitts wrote:
Why do you want to enforce a static method to exist in children? I can
think of no good reason for it.
And I also want to enforce constructors. I provided two use-cases.
1. serialization frameworks. It is already required that a
Serializable class has a no-arg constructor. But this is not required
at compile time.
You've said this a couple times, but are you sure it's true?
This class (with no no-arg constructor) appears to serialize and
deserialize just fine:
Only the non-Serializable Base of a Serializable class requires a
no-args constructor:
<http://java.sun.com/javase/6/docs/api/java/io/Serializable.html>
To allow subtypes of non-serializable classes to be serialized, the subtype may assume responsibility for saving and restoring the state of the supertype's public, protected, and (if accessible) package fields. The subtype may assume this responsibility only if the class it extends has an accessible no-arg constructor to initialize the class's state. It is an error to declare a class Serializable if this is not the case. The error will be detected at runtime.
During deserialization, the fields of non-serializable classes will be initialized using the public or protected no-arg constructor of the class. A no-arg constructor must be accessible to the subclass that is serializable. The fields of serializable subclasses will be restored from the stream.
Anyway, if you are developing frameworks, then you might just have to
settle for runtime validation of these constraints, or invent your own
language that enforces them.
--
Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>