如果你想使用一个类的是静态变量和方法,一般这样使用:
Classs A;
STATIC_VAR;
-------------
import A
A.STATIC_VAR;
也可以把全局的静态变量放在接口里:
interface Constants
STATIC_VAR
--------------
import Constants
Constants.STATIC_VAR;
JAVA 5.0 中提供一种新方法:
import static A.STATIC_VAR;
// or import static Constants.STATIC_VAR;
STATIC_VAR
这样静态变量就可以[b][size=large]直接[/size][/b]使用了.
优势分析:
代码是不是变短了.
用法:
import static java.lang.Integer.parseInt; //导入静态方法
import sattic java.lang.Math.*; // 导入Math中所有静态成员
Classs A;
STATIC_VAR;
-------------
import A
A.STATIC_VAR;
也可以把全局的静态变量放在接口里:
interface Constants
STATIC_VAR
--------------
import Constants
Constants.STATIC_VAR;
JAVA 5.0 中提供一种新方法:
import static A.STATIC_VAR;
// or import static Constants.STATIC_VAR;
STATIC_VAR
这样静态变量就可以[b][size=large]直接[/size][/b]使用了.
优势分析:
代码是不是变短了.
用法:
import static java.lang.Integer.parseInt; //导入静态方法
import sattic java.lang.Math.*; // 导入Math中所有静态成员