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

 

 

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

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

 

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

导入类:

 

 
  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. }

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值