[1880] in java-interest
Q:ambigous method ?
daemon@ATHENA.MIT.EDU (Christophe Meessen)
Tue Sep 19 08:11:50 1995
Date: Tue, 19 Sep 1995 11:26:13 +0200
To: java-interest@java.Eng.Sun.COM
From: meessen@cppm.in2p3.fr (Christophe Meessen)
Hello,
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.
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 ?
---------
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 ?
---------
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 ?
TIA (thanx in advance)
Bien cordialement,
Ch.Meessen
-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com