0

I wrote this program in net-beans. It says I can't pass 'null' value to a method (overloaded) when there is a overloaded method which accept a String and a overloaded method which accept a Object.

reference to enroll is ambiguous both method enroll(java.lang.String) in object.Str and method enroll(object.Object) in object.Str match

Then I ran the same program with cmd. And It compiled well. Null value has passed to the method which accept a String. output -

String

Why that happens like that?

The code

class Str {
void enroll(String du){
    System.out.println("String");
}
void enroll(Object o){
    System.out.println("Object");
}}


class worker{
public static void main(String[] args) {
    Str s = new Str();
    s.enroll(null);
}}
  • The problem is NetBeans. It seems to have a problem with detecting edge (and not so edge) cases in applying JLS overloading resolution. In this case the JLS says the most specific method is chosen, as demonstrated by the command-line version. NetBeans is confused. – Jim Garrison Jul 19 '16 at 04:58
  • I guess, its not exactly duplicate. Problem is same and answers to other duplicate question specify as what needs to be done to solve it. Other part of question - **Then I ran the same program with cmd. And It compiled well** remains unanswered about difference in behavior between cmd and IDE. OP can clarify if I understood it correctly. – Sabir Khan Jul 19 '16 at 05:04
  • As I said in my comment, NetBeans is broken in this regard. I've seen other weird problems around overload resolution being incorrectly flagged as ambiguous in NetBeans. I suggest you file a bug against NetBeans. I would do it but I don't use NetBeans (I use Eclipse). – Jim Garrison Jul 19 '16 at 05:07

0 Answers0