Re: which foo(x)
From: Rick Trotter (rht325_at_yahoo.com)
Date: 12/30/03
- Previous message: S C A: "Re: Anyone know about ActiveX in Java?"
- In reply to: Daniel Bonniot: "Re: which foo(x)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 30 Dec 2003 11:48:26 -0800
Daniel,
Thanks for your response.
With the help of the responses to my posting, I have worked my way
towards a rationalization of this behavior.
At compile time I indicated that I wanted the method with signature
foo(ClassX) to be invoked. In implementing ClassB.foo(ClassY) I was
thinking that I was overriding ClassA.foo(ClassX).
Sloppy thinking on my part. Conceptually, the latter cannot be an
override of the former precisely because it is more restrictive. (I
suppose I was expecting the runtime to treat it as an override when it
"could" be treated as such.) Moreover, the latter has no special
relationship in Java to the former at all; it is simply a different
method with the same name.
The fact that Java allows me to reuse the name in this scenario (where
ClassY extends ClassX) is what I would call a "pitfall", because my
mistake seems to me like an easy mistake to make.
So I need to train myself to do something like what's done in your
Point example. Implement a method with precisely the the same
signature, test the argument and cast or delegate to super as
appropriate.
Thanks,
-Rick
Daniel Bonniot <Daniel.Bonniot@inria.fr> wrote in message news:<3FE0AF29.3070005@inria.fr>...
> while Java programmers need to write:
>
> class Point
> {
> private int x;
>
> public boolean equals(Object that) {
> if (that instanceof Point) {
> Point thatPoint = (Point) that;
> return this.x == thatPoint.x;
> } else {
> return super.equals(that);
> }
> }
> }
- Previous message: S C A: "Re: Anyone know about ActiveX in Java?"
- In reply to: Daniel Bonniot: "Re: which foo(x)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|