Re: which foo(x)

From: Rick Trotter (rht325_at_yahoo.com)
Date: 12/30/03

  • Next message: Robert: "Hard Disk ID"
    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);
    > }
    > }
    > }


  • Next message: Robert: "Hard Disk ID"

    Relevant Pages

    • Re: Repeated read From Socket is Truncated
      ... to return control back to the client code. ... Maybe the size of the response is fixed reads in data ... can't Java do that. ... int readSum = 0; ...
      (comp.lang.java.programmer)
    • Re: IE error when closing
      ... Don, thanks for the response. ... Adobe and Java which both work with IE on certain sites. ... >> found more then one post who never had the issue until they got SP2. ...
      (microsoft.public.windows.inetexplorer.ie6.browser)
    • C# generated .NET stubs break on a null return of a complex object
      ... I have a SOAP written in Java, and being served by Apache Axis - using the ... When I make this same call with my java client - here is the SOAP message ... the response object is basically empty - because there were ...
      (microsoft.public.dotnet.framework.webservices)
    • Re: Java beginners and GUIs (was Re: simple sound problem)
      ... > perspective of learning and understanding Java, ... When I wrote that I didn't see a reason why it ... married to any single pedagogy for teaching Java. ... > section of Andrew's response would have appeared. ...
      (comp.lang.java.programmer)
    • Classic RW 2 (was: Rounding errors
      ... Let's look at how changing logic is used in a classic RW response ... > don't know about compiled Java). ... If the original statement had been, ... You may be right when you said ' rounding mechanism is well ...
      (comp.lang.cobol)