包命名规则及包的导入注意

包命名规则及包的导入注意

 

 

导入包使用.*不会影响运行时速度,,只会影响编译速度,,建议还是用啥导入啥,,不要.*

包命名规则及包的导入注意

注意   上图中有个静态导入哈

 

使用静态导入可以使被导入类的静态变量静态方法在当前类直接可见,使用这些静态成员无需再给出他们的类名。

导入类:

 

 
  1. package com.learn.comm;

  2.  
  3. public class Common {

  4.  
  5. public static final String HELLO = "hello world!";

  6.  
  7. public static void show()

  8. {

  9. System.out.println("hello world!");

  10. }

  11. }


正常导入:

 

 
  1. package com.learn.imports;

  2.  
  3. import com.learn.comm.Common;

  4.  
  5. public class Test {

  6. public static void main(String[] args) {

  7. System.out.println(Common.HELLO);

  8. Common.show();

  9. }

  10. }

静态导入:

 

 
  1. package com.learn.imports;

  2.  
  3. import static com.learn.comm.Common.HELLO;

  4. import static com.learn.comm.Common.show;

  5.  
  6. public class StaticImportTest {

  7. public static void main(String[] args) {

  8. System.out.println(HELLO);

  9. show();

  10. }

  11. }

静态导入的是类的静态成员变量和静态方法