由于import语句允许使用没有包限定条件的类,因此静态导入允许访问没有类限定条件的类的静态成员。例如,要访问静态方法,您需要调用using类名-
Math.sqrt(169);
但是,使用静态导入可以直接访问静态方法。
import static java.lang.Math.*;
public class Sample{
public static void main(String args[]){
System.out.println(sqrt(169));
}
}输出结果
13.0