在匿名内部类的代码处:
HashMap<String, String> map3 = new HashMap<>() {
{
put("A", "1");
put("B", "2");
}
};
这串代码我在1.8版本java中eclipse中编译错误。是为什么?
在hashmap下面报错:'<>' cannot be used with anonymous classes。
用教程推荐的JDK版本:
补全泛型
HashMap<String, String> map3 = new HashMap<String, String>() {
Sign in to make a reply
尾丶行痴汉
在匿名内部类的代码处:
HashMap<String, String> map3 = new HashMap<>() {
{
put("A", "1");
put("B", "2");
}
};
这串代码我在1.8版本java中eclipse中编译错误。是为什么?