所谓的导入不占用任何资源,只是让我们在编写代码的时候少写一些包名、前缀。
例如:我们要求两个数的最大值,或者我们要求某个数的绝对植。
还有常用的Math.random();
3和6的最大值。
Math.max(3,6);
3-6的绝对值
Math.abs(3-6);
如果我们想直接些方法名,那么可以使用静态导入。
import static java.lang.Math.max;
import static java.lang.Math.abs;
或者
import static java.lang.Math.*;
使用该静态导入必须在JDK1.5之后。
例如:我们要求两个数的最大值,或者我们要求某个数的绝对植。
还有常用的Math.random();
3和6的最大值。
Math.max(3,6);
3-6的绝对值
Math.abs(3-6);
如果我们想直接些方法名,那么可以使用静态导入。
import static java.lang.Math.max;
import static java.lang.Math.abs;
或者
import static java.lang.Math.*;
使用该静态导入必须在JDK1.5之后。