aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes About polymorphism Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "About polymorphism" Watch "About polymorphism" New topic
Author

About polymorphism

Jack Lau
Ranch Hand

Joined: Aug 30, 2002
Posts: 166
Could anyone tell me why compiler show the following error message ?
"reference to m is ambiguous, both method m(B, B) in C and method m(A, C) in C match m(c, c)."

But if I change m(A x, C y) to m(B x, C y) will work properly.
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
This question was just answered within the last few days.


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
I'll try, but I do not feel 100% that I understand it myself; so beware.
The compiler must try to decide which of m(B, B) or m(A, C) is "most specific" to the actual call which is type m(C, C). If we choose the m(B, B) case we can object because the second argument is a C, so m(A, C) is "more specific". If we choose the m(A, C) case we can object because the first argument is a C which is a B, so m(B, B) is "more specific". Because we can object in both cases it cannot be decided which of the two methods to call.
When you change the m(A, C) to m(B, C) we can choose m(B, C) because the second argument is a C which is more "specific" than it being a B.
Is there some easy algorithm for resolving these things?
-Barry


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
I think Thomas means here.
Jack Lau
Ranch Hand

Joined: Aug 30, 2002
Posts: 166
Thank you very much!
I think I got what you mean.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: About polymorphism