I am doing a static import of members of class Long and Integer:
import static java.lang.Integer.MAX_VALUE;
import static java.lang.Long.MAX_VALUE;
Now if I am trying to use this variable MAX_VALUE and print it I will get an error:
import static java.lang.Integer.MAX_VALUE;
import static java.lang.Long.MAX_VALUE;
public class StaticImportDemo2 {
public static void main(String[] args) {
//Error :: The field MAX_VALUE is ambiguous
System.out.println("Print without static import Integer.MAX_VALUE "+MAX_VALUE);
}
}
This is fine. To remove the error i will have to remove one static import to resolve this ambiguity .
The main issue I am getting is, if I use wildcard *
with Integer class
static import, the class gets compiled with no errors:
import static java.lang.System.out;
import static java.lang.Integer.*;
import static java.lang.Long.MAX_VALUE;
public class StaticImportDemo2 {
public static void main(String[] args) {
System.out.println("Print without static import Integer.MAX_VALUE " + MAX_VALUE);
}
}
The ambiguity must still exist. Why does this compile with no issues?