//interface1.java
package package1;
public interface interface1 {
static final int a =10;
}
//StaticImportTest.java
import static package1.*; //import package1.*; works
class StaticImportTest {
public static void main(String args[]) {
System.out.println(a); //System.out.println(interface1.a) works
}
}
when i am replacing the word "import static" with only "import" and using System.out.println(interface1.a) it works, but not sure why its not working in its current form.
For your static import to work the way you intended it would have to be
import static package1.interface1.*orimport static package1.interface1.aA static import imports public static members of a class either all with * or a specific one like for example
a.A import on the other hand imports a package or specific classes from a package.
Your
import static package1.*would try to import all members from the classpackage1in the root package.Making it a normal import and accessing
aviainterface1.aworks because the import imports all classes from thepackage1includinginterface1, therefor you can accessavia theinterface1class.