要生成的源代码
class SomeClass{
public void someMethod(){
HashMap<String,String> map = new HashMap<String,String>();
}
}
能够创建为全局变量,但我需要在方法中创建它
JClass keyType = codeModel.ref(Object.class);
JClass valueType = codeModel.ref(Object.class);
JClass mapClass = codeModel.ref(Map.class).narrow(keyType, valueType);
JClass hashMapClass = codeModel.ref(HashMap.class).narrow(keyType, valueType);
headers = definedClass.field(JMod.PRIVATE, mapClass, "headers").init(JExpr._new(hashMapClass));