JDK5-静态导入

import static

 

1. 导入一个类内所有静态成员

1 import static java.lang.Math.*;
2 
3 public class StaticImport {
4     public static void main(String[] args) {
5         System.out.println(max(2, 3));
6     }
7 }

2. 导入一个静态函数

1 import static java.lang.Math.random;
2 
3 public class StaticImport {
4     public static void main(String[] args) {
5         System.out.println(random());
6     }
7 }

 

posted on 2016-11-01 12:53  Joshua_AW  阅读(116)  评论(0编辑  收藏  举报

导航