"ambiguous for the type" error where all is import

P

poorichard

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
 
C

Chris Uppal

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
 
I

Ingo R. Homann

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
 
P

poorichard

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top