// "Fix all 'Map.forEach() can be used' problems in file" "true" import java.util.Map; import java.util.function.Supplier; public class Test { public static void testInline(Map map) { map.entrySet().forEach(entry -> System.out.println(entry.getKey() +":"+entry.getValue()) ); } public static void testKey(Map map) { map.entrySet().forEach(entry -> { String str = entry.getKey(); System.out.println(str +":"+entry.getValue()); }); } public static void testValue(Map map) { map.entrySet().forEach(entry -> { String str = entry.getKey(); Integer num = entry.getValue(); System.out.println(str +":"+ num); }); } public static void testTwoVarsWildcard(Map map) { map.entrySet().forEach(entry -> { String str = entry.getKey(); Integer num = entry.getValue(); System.out.println(str +":"+ num); String str2 = entry.getKey(); System.out.println(str2); }); } public static > void testGeneric(Supplier map) { map.get().entrySet().forEach(e -> System.out.println(e.getKey()+":"+e.getValue())); } public static > void testUsedHashCode(Supplier map) { map.get().entrySet().forEach(e -> System.out.println(e.getKey()+":"+e.getValue()+":"+e.hashCode())); } public static void testForLoop(Map map) { for (Map.Entry entry : map.entrySet()) { System.out.println(entry.getKey() + ":" + entry.getValue()); } } public static void testForLoop2(Map map) { for (Map.Entry entry : map.entrySet()) { String str = entry.getKey(); Integer num = entry.getValue(); System.out.println(str + ":" + num); } } public static void testForLoop3(Map map) { for (Map.Entry entry : map.entrySet()) { String str = entry.getKey(); Integer num = entry.getValue(); System.out.println(str + ":" + entry.getValue()); System.out.println(num + ":" + str); } } public static void testForLoopSet(Map map) { for (Map.Entry entry : map.entrySet()) { String str = entry.getKey(); Integer num = entry.getValue(); System.out.println(str + ":" + entry.getValue()); entry.setValue(1); } } public static void testForLoopPrimitive(Map map) { for (Map.Entry entry : map.entrySet()) { String str = entry.getKey(); int num = entry.getValue(); System.out.println(str + ":" + num); } } public static void testForLoopSideEffect(Map map) { Integer num; for (Map.Entry entry : map.entrySet()) { String str = entry.getKey(); num = entry.getValue(); System.out.println(str + ":" + num); } } public static void testForLoopThrow(Map map) throws Exception { for (Map.Entry entry : map.entrySet()) { String str = entry.getKey(); Integer num = entry.getValue(); if(num > 0) throw new Exception(); System.out.println(str + ":" + num); } } public static void testForLoopThrowRuntime(Map map) throws Exception { for (Map.Entry entry : map.entrySet()) { String str = entry.getKey(); Integer num = entry.getValue(); if(num > 0) throw new RuntimeException(); System.out.println(str + ":" + num); } } void forEach(Map map) { for (Map.Entry entry : map.entrySet()) { //long comment } } void expressionStatement(Map map) { for (Map.Entry entry : map.entrySet()) { String value = entry.getValue(); entry.getValue(); } } }