我已经宣布了这个课程:
public final class Constants { public static final String PROFILE_PCT__FILTER_NAME_ID = "profilePct"; }
我想在另一个类中使用该类...
import static com.tdk.utils.Constants.*;
但是我得到了这个编译错误:
常量无法解析为变量
当您使用 * 进行静态导入时,您可以访问类中定义的变量 . 但是,您无法引用类本身 .
*
Should work:-
import static com.tdk.utils.Constants.*; String a =PROFILE_PCT__FILTER_NAME_ID;
Shouldn't work:-
String a =Constants.PROFILE_PCT__FILTER_NAME_ID;
您需要以下导入来解决编译问题 .
import com.tdk.utils.Constants;
1 回答
当您使用
*
进行静态导入时,您可以访问类中定义的变量 . 但是,您无法引用类本身 .Should work:-
Shouldn't work:-
您需要以下导入来解决编译问题 .