当Constants类中常量值越来越多的时候,为方便管理不同类型的常量值,可以有如下比较清楚的静态内部类写法。
public class Constants {
public static final class URL{
public static final String BAIDU = "https://www.baidu.com";
public static final String TENGXUN = "https://www.qq.com/";
}
public static final class NAME{
public static final String CHINEY = "chiney";
public static final String SHERRY = "sherry";
}
public static void main(String[] args) {
String url = Constants.URL.BAIDU;
String name = Constants.NAME.CHINEY;
System.out.println(name + " is using " + url);
}
}
网友评论