• Post Reply Bookmark Topic Watch Topic
  • New Topic

Java compiler error  RSS feed

 
Sri Yasasvi
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • 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
 
Joachim Rohde
Ranch Hand
Posts: 433
Netbeans IDE
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Thanks For your Answer. It works!!!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!