Constants更清楚的写法

2018-12-18  本文已影响0人  晨钟初磬

当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);
        
        
    }
    
    
    

}
上一篇下一篇

猜你喜欢

热点阅读