包命名规则及包的导入注意
导入包使用.*不会影响运行时速度,,只会影响编译速度,,建议还是用啥导入啥,,不要.*
注意 上图中有个静态导入哈
使用静态导入可以使被导入类的静态变量和静态方法在当前类直接可见,使用这些静态成员无需再给出他们的类名。
导入类:
-
package com.learn.comm;
-
public class Common {
-
public static final String HELLO = "hello world!";
-
public static void show()
-
{
-
System.out.println("hello world!");
-
}
-
}
正常导入:
-
package com.learn.imports;
-
import com.learn.comm.Common;
-
public class Test {
-
public static void main(String[] args) {
-
System.out.println(Common.HELLO);
-
Common.show();
-
}
-
}
静态导入:
-
package com.learn.imports;
-
import static com.learn.comm.Common.HELLO;
-
import static com.learn.comm.Common.show;
-
public class StaticImportTest {
-
public static void main(String[] args) {
-
System.out.println(HELLO);
-
show();
-
}
-
}
静态导入的是类的静态成员变量和静态方法