关于import static

静态导入,是对于import语句的加强,使其不仅能让你省略包名,还能省略静态方法/字段所在类的类名。也就是说,静态导入允许你在调用其它类中定义的静态成员时,忽略类名。

package test;

import static java.lang.Math.max;//导入了Math的max方法

public class StaticImportTest{

public static void main(String[] args) {

System.out.println(max(1, 2));//不用写Math了

 	}

 }

猜你喜欢

转载自blog.csdn.net/weixin_43805219/article/details/86594149