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
...
}
.



Relevant Pages

  • Re: static abstract methods
    ... In my case I don't need to use it polymorphically I just need to enforce an ... >> How would you force a derived class to implement a static method? ... > If replying to the group, please do not mail me too ... Prev by Date: ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Simple question about instantiating
    ... Is the constructor also only for the class (almost like a static method) that is run each time an object is instantiated? ... And if that is the case, then all the 10 objects that are created really have nothing in them because the class variable belongs to the class, the constructor also belongs to the class and finally also the public static int getInstanceCountmethod? ... That said, as the name implies, a CountTest does not seem to ... references the CountTest that was created by its initializer, ...
    (comp.lang.java.programmer)
  • Re: Static generic extension method
    ... excellently done by extension methods, ... XML serialization is coded in one place only). ... Since XmlSerializer itself seems to me like a giant static method (you can ... and they're good for readability as they preserve traditional O-O ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: throwing exception from constructor
    ... This would create a three-state stream - closed, ... appropriate arguments to the FileStream constructor. ... one calls the static method rather than using the constructor, ... extra complexity, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: denotes field where class expected and other problem
    ... There's no way you can reference the this pointer within a static method ... The constructor expects to receive an object then u ... I want to reference it in the class. ... > In the netclass class: ...
    (microsoft.public.dotnet.languages.csharp)