88.Java静态导入

静态导入

JDK 1.5 增加的静态导入语法用于导入类的某个静态属性或方法。使用静态导入可以简化程序对类静态属性和方法的调用。

语法:

import static 包名.类名.静态属性|静态方法|*

例如:

import static java.lang.System.out

import static java.lang.Math.*

import static java.lang.System.out;
import static java.lang.Math.*;

public class Demo {

    public static void main(String[] args) {
        // 普通写法
        System.out.println("hello world");
        int max = Math.max(100, 200);
        System.out.println(max);

        // 静态导入
        out.println("hello world");
        int max2 = max(100, 200);
        System.out.println(max2);
    }
    
}
author@nohert
原文地址:https://www.cnblogs.com/gzgBlog/p/13624057.html