Why don't you have a static and non-static method with the same method signature in Java?

Actually it does not make sense to me. Maybe someone can help me understand. It seems silly that I have to switch the order of my parameters in order to have this function.

+4
source share
2 answers

Since Java allows you to call the method staticnon-statically, i.e. on the class object. So, if a class has methods staticand non-static- of method()the same signature, such a call: obj.method()will be ambiguous.

+10
source

Because:

class Example {

   void method () { }

   static void method () { }

   void example () {
      method();   // <- ambiguous
   }

}

, , , . Example. . .

, , , , , , , , .

" " kludge, . , . , .

+4

All Articles