HashMap,为什么putAll语句不能放在for(Map.Entry)语句之后

为什么putAll语句不能放在for(Map.Entry)语句之后
这个代码不会报错
    public static void main(String[] args) {
        
        HashMap<String,Integer> h1=new HashMap<String,Integer>();
        h1.put("A", 1);
        h1.put("B", 2);
        HashMap<String,Integer> h2=new HashMap<String,Integer>();
        h2.put("C",3);
        
        h2.putAll(h1);    
        for(Map.Entry m: h2.entrySet())
        {
            System.out.println(m.getKey()+" "+m.getValue());}
        }

但是这段代码会报错

    public static void main(String[] args) {
        
        HashMap<String,Integer> h1=new HashMap<String,Integer>();
        h1.put("A", 1);
        h1.put("B", 2);
        HashMap<String,Integer> h2=new HashMap<String,Integer>();
        h2.put("C",3);
        
        for(Map.Entry m: h2.entrySet())
        {
            System.out.println(m.getKey()+" "+m.getValue());}
        }
        h2.putAll(h1);    

img

区别只是putall代码在Map.Entry代码的前面还是后面

运行结果及报错内容

报错内容为:
Multiple markers at this line
- Syntax error on token ".", @ expected after this token
- Syntax error, insert "SimpleName" to complete QualifiedName
- Syntax error, insert "Identifier (" to complete
MethodHeaderName
- Syntax error, insert ")" to complete MethodDeclaration

希望能有人解答,感谢!

你的括号是不是没对好。。放在方法外了吧,怎么循环里面有个花括号的。。