我正在HashMap
函数内创建一个带有双括号的内联:
public void myFunction(String key, String value) {
myOtherFunction(
new JSONSerializer().serialize(
new HashMap<String , String>() {{
put("key", key);
put("value", value.);
}}
)
);
}
我收到这些错误:
myClass.java:173: error: local variable key is accessed from within inner class; needs to be declared final
put("key", key);
^
myClass.java:174: error: local variable value is accessed from within inner class; needs to be declared final
put("value", value);
^
2 errors
如何将方法参数插入到Object
初始化的双括号中?