/*
* 静态导入
*
* 格式:import static 包名...类名.方法名
* 可以最直接导入方法级别
*
* 静态导入的注意事项
* A:方法必须是静态的
* B:如果有多个同名的静态方法,容易不知道使用谁?
* 这个时候要使用,必须要加上前缀
* 所以静态导入意义一般不大,但是了解
*/
import static java.lang.Math.abs;
import static java.lang.Math.pow;
import static java.lang.Math.max;
public class JDK5的新特性静态导入 {
public static void main(String[] args) {
// System.out.println(java.lang.Math.abs(-100));
// System.out.println(java.lang.Math.pow(2, 3));
// System.out.println(java.lang.Math.max(15, 4565));
//太复杂,我们引入了import
// System.out.println(Math.abs(-100));
// System.out.println(Math.pow(2, 3));
// System.out.println(Math.max(15, 4565));
//太复杂,我们有更简单的
System.out.println(java.lang.Math.abs(-100));
System.out.println(pow(2, 3));
System.out.println(max(15, 4565));
}
//B:如果有多个同名的静态方法,容易不知道使用谁?
// 这个时候要使用,必须要加上前缀
public static void abs(String s) {
System.out.println(s);
}
}
JDK5的新特性静态导入
最新推荐文章于 2025-04-10 16:33:23 发布