Re: Implicit type parameters
SoulSpirit@gmail.com wrote On 01/30/07 10:21,:
[...]
And I'd like to force subclasses to implement this compareToInternal()
method that compares only instances of the same type (Dogs with Dogs
and Cats with Cats).
An implementation like this...
public class Dog extends Animal<Cat>{
int compareToInternal( Cat other ){
return 0;
}
}
... should be seen as an error by the compiler.
I don't think you can do that. An abstract class (or an
interface) can require its subclasses (implementors) to provide
methods with particular signatures, but it cannot prevent them
from providing other methods as well. Those other methods may
have the same names as some of the required methods (that's
called "overloading"), but they are distinct methods. Java
will allow the subclass to provide all of
int compareToInternal(String attached) { ... }
int compareToInternal(double trouble) { ... }
int compareToInternal(char broiled) { ... }
int compareToInternal(float aLoan) { ... }
int compareToInternal(int p, int q, int r) { ... }
.... and there's nothing (as far as I know) you can do to
prevent it.
--
Eric.Sosman@sun.com