[1909] in java-interest
Re: Q:ambigous method ?
daemon@ATHENA.MIT.EDU (Arthur van Hoff)
Tue Sep 19 20:15:57 1995
Date: Tue, 19 Sep 1995 13:10:13 -0800 (PDT)
From: Arthur van Hoff <Arthur.Vanhoff@Eng.Sun.COM>
Reply-To: Arthur van Hoff <Arthur.Vanhoff@Eng.Sun.COM>
To: Christophe Meessen <meessen@cppm.in2p3.fr>
Cc: java-interest@java.Eng.Sun.COM
Hi Christophe,
> I'm curently implementing a class for wich I want to have an equals method.
> Though at compilation time I have the following error message:
>
> TestXXX.java:61: Reference to equals is ambiguous. It is defined in boolean
> equals(cppm.XXX) and boolean equals(java.lang.Object).
> println( x1.equals( x2 ) );
> ^
> What does it mean ?
> x1 and x2 are declared as XXX instances.
>
> I thought I was overriding the Object.equals method.
If you want to override the Object.equals method it must have the exact same
method signature. Java doesn't support covarient typing of arguments.
> The fact that XXX is a class implementing an interface may be influencing.
> XXX is declared the following way
>
> public class XXX implements theXXX {
> ...
> }
>
> But the XXX.equals method is not part of the interface. It is defined in the
> implementation method.
>
> on page 8 of the reference manual it is clearly said that all class derived
> from
> a single root class: Object. So I don't understand where the ambiguity is.
>
> Note: the println method I call is a TestXXX method that just call the
> System.out.println. It is for readability that I used this trick.
>
> ---------
>
> I have another question regarding this point. I want to define a set of
> class types. I want to be able to define an array contaning any instances of
> one of these classes and exclude any other.
>
> I see two ways to do it: Define an abstract superclass common to all these
> classes or define an interface that each class implements.
> From what I understood both methods should work. But What is the right
> and/or the best way to do that ? What is the difference ?
You can also use an interface.
> ---------
>
> Beside, I apreciated the implicit rule of using a capital letter as the
> first letter of class types. I regret that this was not extended to all
> types like
> int float boolean for consistency. What is the logic behind this rule ?
int and float are not class types, they are simple types.
> ---------
>
> The length variable in array classes is some sort of exception to the nice
> orthogonality of the java language. To get the length of an array we do
> a.length. Shouldn't this be a method ?
It could have been. Just think of it as a final instance variable.
Have fun,
Arthur van Hoff
-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com