Re: abstract static methods (again)
On Tue, 20 Oct 2009 00:05:41 +0100, Tom Anderson wrote:
On Mon, 19 Oct 2009, Tomas Mikula wrote:
On Mon, 19 Oct 2009 21:05:05 +0100, Tom Anderson wrote:
http://urchin.earth.li/~twic/Code/MutuallyRecursiveGenerics/
Vector.java
The VectorKind should also have two type parameters to get rid of
compiler warnings and to map Vectors to VectorKinds one-to-one:
abstract class
VectorKind<V extends Vector<V,K>, K extends VectorKind<V,K>>
It compiled without warnings for me - but then i'm on 1.5.
I haven't tried to compile it, but I suppose that the compiler should
issue a warning on line
abstract class VectorKind<V extends Vector>
because Vector is a raw type.
Anyway, this is not of any help for me, because you are obtaining the
VectorKind instance from an instance of Vector. If there is always an
instance of Vector at hand, I can obtain the zero directly from that
instance (just move the abstract zero() method you declared in
VectorKind to Vector). The problem is that there is not always an
instance at hand and it is cumbersome to artificially pass one.
What are you planning to do with this zero if you don't have any Vector
instances? I don't really buy your scenario.
Consider you want to implement a method that takes a collection of
vectors and returns their sum. Simple, eh? If I can call static methods
on type parameters, it will look like this:
public V sum(Collection<V> coll){
V s = V.zero();
for(V v: coll)
s = s.add(v);
return s;
}
However, we cannot call V.zero(). What will you return if coll is an
empty collection?