在項目中有個場景:已知a,b,c,d,若傳四個中的一個則返回傳入的值,否則則默認返回a;
看到這個問題,就想到要把a,b,c,d這幾個放到一個靜態變量中,但是腦子竟然轉不來,怎么去初始化,看來平時代碼copy多了!
public class example{ public static final Map<String,String> map = new HashMap<String,String>() ; static { map.put("a","this is a") ; map.put("b","this is b") ; map.put("c","this is c") ; map.put("d","this is d") ; } }