• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Java compiler error

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I am trying to compile the below code.

public class Test{

public static void main(String args[]){
Test question = new Test();
question.method(null);
}
public void method(StringBuffer o){
System.out.println("Object Verion");
}
public void method(String s){
System.out.println("String Version");
}

}

But i am getting error like The method method(StringBuffer) is ambiguous for the type Test.

I am looking if any one could explain me about this error.

Thanks,
Yasasvi
 
Ranch Hand
Posts: 433
Netbeans IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The compiler does not know which method you'd like to call, because it cannot determine which datatype the argument is. You have to cast the argument.
So question.method((StringBuffer)null); should work.
 
Sri Yasasvi
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks For your Answer. It works!!!
 
reply
    Bookmark Topic Watch Topic
  • New Topic