It makes sense. Suppose javac does what you want, it selects your assertEquals(MyObj, MyObj) today. What if tomorrow org.junit.Assert adds its own assertEquals(MyObj, MyObj) method assertEquals(MyObj, MyObj) ? The call value of assertEquals(mo1,mo2) has changed dramatically if you don't know it.
The question makes sense of the name assertEquals . Javac should decide that this is the name of the method (s) in org.junit.Assert . Only after that it can overload the method permission: consider all the methods in org.junit.Assert with the name assertEquals , select the most suitable one.
It can be assumed that java can handle overloading methods from several classes, however, as the first paragraph shows, this causes great uncertainty for the developer of the class that he calls. Since these classes are not related to each other, the semantics of the method can vary greatly.
If, during compilation, without a doubt, you develop a class to which this method belongs, it is still possible that the class will overload the method tomorrow and then change the called method. However, since this is done by the same class, we can assign responsibility to it. For example, if org.junit.Assert decides to add a new assertEquals(MyObj, MyObj) method assertEquals(MyObj, MyObj) , he should know that some previous calls to assertEquals(Object,Object) now redirected to the new method, and he must make sure that there are no semantics changes that Call sites will be broken.
source share