posting-account=pAbxHwoAAAADCfRr12ntKYVMSzbDntdj
Tomas Mikula wrote:
On Wed, 21 Oct 2009 06:10:02 +0100, Steven Simpson wrote:
In fact, since you expect (from the previous question) that any Y
which extends X must provide its own static run(), I don't see a point
in requiring X to 'implements static Runnable' if it's only going to
leave the implementation to a base class.
The point would be to enforce the subclasses to 'implement static'
Runnable. Consider again an abstract class Vector with static method
zero(), which should return a zero vector. Vector alone doesn't need
(even can't reasonably) implement zero(), but it wants to enforce its
implementation in all concrete subclasses.
I anticipated shortly after posting that your Vector example might be
what you were getting at. Here's how I think it would go (assuming
reified generics). Your original declaration:
class MyClass<V extends Vector<V>> {
public void someMethod(){
V v = V.zero();
...
}
}
So, on some class whose full implementation you don't know about, you
expect a (V zero()) method - so define an interface type for that:
interface Zero<V> {
V zero();
}
Now express two constraints on the type provided to MyClass:
class MyClass<V extends Vector<V> & V extends static Zero<V>> {
public void someMethod(){
V v = V.zero();
...
}
}
Does that work for you?
Yes, that would work for me. But you need to add a new syntax, namely the