What I am having is two classes which go like this.
public class Class1 {
public static void staticMethod1(){}
public static void staticMethod2(){}
public static void commonStaticMethod(){}
}
And class 2 as
import static Class1.*;
public class Class2 {
public static void commonStaticMethod(){}
}
And to my surprise, this had compiled without any errors and even warnings. So how the static imports escapes from overloading?
Static imports are not overloading. They are merely syntactic sugar to make the use of static methods from other classes shorter.
That is, when a method is called that is not available in the current context then it checks the static imports to see if there is a matching static method.
So
staticMethod()would expand toSomeOtherClass.staticMethod()In your particular case there is no conflict as you do not attempt to call
commonStaticMethod. Were you to do so the compiler will either complain of an ambiguity or default to the static method in the current class (I’m not to sure which — I don’t use * in static imports). But this is something you can easily check for yourself.