我想导入包含consts和类Constants中的常量。我有内部课程。
例如,我想使用表单Capability.DEVICE_NAME
代替Constants.Capability.DEVICE_NAME
public class Constants {
public class Capability{
public final static String DEVICE_NAME = "deviceName";
public final static String PLATFORM_NAME = "platformName";
public final static String PLATFORM_VERSION = "platformVersion";
public final static String APP_PACKAGE = "appPackage";
public final static String APP_ACTIVITY = "appActivity";
}
}
它必须在内部课程中!
提前感谢。
答案 0 :(得分:5)
您必须按以下方式导入您的课程
import packageName.Constants.Capability;
您可以按照以下方式使用:
System.out.println(Capability.DEVICE_NAME);
或者您可以将您的课程设为静态并导入如下。
import static com.Constants.*;
答案 1 :(得分:4)
此import packagename.Constants.*;
应该有效。
或者您可以使嵌套类静态
public class Constants {
public static class Capability{
public final static String DEVICE_NAME = "deviceName";
public final static String PLATFORM_NAME = "platformName";
public final static String PLATFORM_VERSION = "platformVersion";
public final static String APP_PACKAGE = "appPackage";
public final static String APP_ACTIVITY = "appActivity";
}
}
并导入静态:
import static packagename.Constants.*;