Why are static imports of static methods with same names legal?

Posted by user1055638 on Stack Overflow See other posts from Stack Overflow or by user1055638
Published on 2012-10-22T10:32:52Z Indexed on 2012/10/22 11:00 UTC
Read the original article Hit count: 184

Filed under:
|
|

Lets say we have these packages and classes:

package p1;

public class A1 {
    public static void a() {}
}

package p2;

public class A1 {
    public static void a() {}
}

package p3;

import static p1.A1.a;
import static p2.A1.a;

public class A1 {
    public static void test() {

    }
}

I am wondering, why the static import of methods is legal (won't result in compile time error) in package p3? We won't be able to use them further in the test() method as such usage will result in the compile time error.

Why it is not the same as with a normal import of classes. Lets say we would like to import classes A1 from packages p1 and p2 into p3:

package p3;
import p1.A1;
import p2.A1;

such import is illegal and will result in the compile time error.

© Stack Overflow or respective owner

Related posts about java

Related posts about import