我想知道使用以下结构是否可靠:
private static final Map<String, String> engMessages;
private static final Map<String, String> rusMessages;
static {
engMessages = new HashMap<String, String> () {{
put ("msgname", "value");
}};
rusMessages = new HashMap<String, String> () {{
put ("msgname", "значение");
}};
}
private static Map<String, String> msgSource;
static {
msgSource = engMessages;
}
public static String msg (String msgName) {
return msgSource.get (msgName);
}
是否有可能NullPointerException
因为msgSource
初始化块将在初始化块之前执行engMessages
?
(关于为什么我不在msgSource
上面的 init.block 末尾进行初始化:只是口味问题;如果所描述的结构不可靠,我会这样做)