Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / July 2006

Tip: Looking for answers? Try searching our database.

"ambiguous for the type" error where all is import

Thread view: 
poorichard@gmail.com - 19 Jul 2006 09:32 GMT
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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.