On 22/06/2006, at 3:17 AM, Martin Cooper wrote:
On 6/21/06, Garrett Rooney <[EMAIL PROTECTED]> wrote:
Is there a reason that Abdera's Base interface defines clone as
returning something other than Object?
This is not good. Unless something changed in the JLS and I missed
it, it is
not legal to have two methods on a class or interface whose signatures
differ only in the return type.
As I recall, and I often recall incorrectly, there was a change in
Java 1.5 that allowed a subclass to override a method and return a
more specific type. Thus, Base.close() overrides Object.clone() such
that when called from a Base instance if is guaranteed to return a
Base instance (plus the generics magic) and called as an Object it
still works but without the extra guarantee.
In other words, both of the following are equivalent except that the
return type is less specific when using the Object variable declaration:
Object base = new Base();
Object clone = base.clone();
and:
Base base = new Base();
Base clone = base.clone();
So except for the fact that IDEs which are still getting support for
generics and other Java 1.5 features (or still getting them right),
this declaration is a really good idea as it adds compiler type
checking.
Martin Cooper
Adrian Sutton
http://www.symphonious.net