JDK1.5新特性4-静态导入

来源:互联网 发布:微信h5软件 编辑:程序博客网 时间:2024/05/19 04:54

个人观点

开发中不用,能看懂即可。

静态导入的具体格式:

import static 包名.类名.静态成员import static 包名.类名.静态方法

通过实例明确概念要点

  • (1) 导入静态成员
import static java.lang.Math.PI;public class StaticImport {    public static void main(String[] args) {        System.out.println(PI);    }}
  • (2) 导入静态方法
import static java.util.Arrays.sort;public class StaticImport {    public static void main(String[] args) {        int[] arr = { 3, 6, 5, 7 };        sort(arr);        for (int i : arr)  // 输出:3 5 6 7             System.out.print(i + " ");    }}
0 0
原创粉丝点击