我已經初始化靜態塊內的哈希映射,我需要訪問哈希映射對象來獲取值,使用它在我的getExpo
方法中的鍵。如何訪問靜態塊內的對象
我的類放在這裏
public class ExampleFactory {
static
{
HashMap<String,Class<?>> hmap = new HashMap<String,Class<?>>();
hmap.put("app", application.class);
hmap.put("expo", expession.class);
}
public void getExpo(String key,String expression)
{
// I need to access the object in static block
Class aclass=hmap.get(key); // it works when i place it inside main method but
// not working when i place the create object for
// Hashmap in static block
return null;
}
}
謝謝,我明白了 – Jessie 2012-04-04 23:15:00