Re: abstract static methods (again)



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.
Other variant is to require some particular constructor or a creator
static method, such as MyClass.readObject(ObjectInputStream) (though this
method is non-static and not mandatory in Serializable).

2. For calling static methods on generics. My example was
abstract class Vector<V extends Vector<V>>{
/** returns a zero vector */
public abstract static V zero();
}

Then somewhere else I would like to use code as this:

MyClass<V implements Vector<V>> { // 'implements' is not valid here now
...
V v = V.zero(); // not possible now
...
}
.