The method is ambiguous for the type compiler error

Code below illustrated couse of The method is ambiguous for the type compiler error.

public class AmbiguousMethodOwner {
            void ambiguousMethod(Comparable c){}
            void ambiguousMethod(Serializable c){}
            void test() {
                   ambiguousMethod("bar");
           }
     }

The problem now is obvious: since String implements both Comparable and
Serializable, the compiler cannot know which method you intend to call.

A simple cast will solve the problem:

      ambiguousMethod((Comparable)"bar");
Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • LinkedIn
  • MySpace
  • RSS
  • Twitter
  • Yahoo! Bookmarks
  • Yahoo! Buzz
  • BlinkList
  • blogmarks
  • DZone
  • E-mail this story to a friend!
  • LinkaGoGo
  • Live
  • MisterWong
  • MisterWong.DE
  • Reddit
  • StumbleUpon
  • Technorati
  • ThisNext
  • Tumblr

No related posts.

Leave a Reply


wp