When I use a static import to import a static method of signature s1
in a class that has a method of the same name, but a different signature s2, I get a compile error when I reference the imported method.
Example:
// Class Provider provides some static method
package staticimport;
public class Provider {
public static void staticMethod(String text) {
System.out.println(text);
}
}
// Class Consumer references the method provided by the Provider class
package staticimport;
import static staticimport.Provider.staticMethod;
public class Consumer {
public static void staticMethod() {
staticMethod("cannotcompile"); // Gives compile error
}
}
The compile error in this example is:
The method staticMethod() in the type Consumer is not applicable for the
arguments (String)
So is it true that
import static <method_name> only "considers" the method's simple name rather than the full signature and shadows all methods (both static and non-static) of the same simple name within the compilation unit, irrespective of the signature, leading to the above error?
Related topics are
http://forum.java.sun.com/thread.jspa?forumID=316&threadID=533658
http://forum.java.sun.com/thread.jspa?forumID=316&threadID=458109
http://forum.java.sun.com/thread.jspa?forumID=316&threadID=458109