Hi,all
I had a strange problem,
the sentence down:
Object[] listeners = ChartPanel.getListeners(ChartMouseListener.class);
will get the complie error "the method getListeners(Class) is ambiguous
for the type chartPanel",
and when convert the ChartMouseListener.class to (Class)
ChartMouseListener.class,
It workds well,
but the ChartMouseListener.class is just a Class,isn't it?
btw,the enviement is JDK1.5 and Elcipse3.1.1,
anyone can explain my puzzle?
best regards,
Richard
Chris Uppal - 19 Jul 2006 10:01 GMT
> Object[] listeners = ChartPanel.getListeners(ChartMouseListener.class);
> will get the complie error "the method getListeners(Class) is ambiguous
> for the type chartPanel",
You don't say how ChartPanel.getListeners() is declared, and especially how
many and what overrides there are of the same method name.
If you are talking about the ChartPanel from JFreeChart, then that appears only
to have or inherit one method with that name. I can't think of any reason why
the compiler should complain about that being ambiguous (there's no way it can
be), so I assume that it's just another a bug in either the Eclipse compiler or
the JDK compiler (you don't say which one is giving you the error).
-- chris
Ingo R. Homann - 19 Jul 2006 10:53 GMT
Hi,
I will post a SSCCE (because you didnt)-:
class Ambiguous {
void foo(Comparable c){}
void foo(Serializable c){}
void bar() {
foo("bar");
}
}
The problem now is obvious: sine String implements both Comparable and
Serializable, the compiler cannot know which method you intend to call.
A simple cast will solve the problem:
foo((Comparable)"bar");
Hth,
Ingo
poorichard@gmail.com - 19 Jul 2006 11:38 GMT
yes,It's from JFreeChart,and appears only to have or inherit one method
with that name
I think.
And then I turned the IDE to Eclipse 3.1.0 , It works now. So maybe the
bug in Eclipse 3.1.1.
Thanks for all.
Richard