You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
770 B

/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import java.util.Map;
class SlowIterTests {
static <K, V> void aBad(Map<K, V> m) {
for (K k : m.keySet()) {
System.out.printf("%s -> %s\n", k, m.get(k));
}
}
static <K, V> void aOk(Map<K, V> m) {
for (Map.Entry<K, V> e : m.entrySet()) {
System.out.printf("%s -> %s\n", e.getKey(), e.getValue());
}
}
// Inter-procedural variant of aBad.
static <K, V> void bBad(Map<K, V> m) {
for (K k : m.keySet()) {
print(k, m);
}
}
static <K, V> void print(K k, Map<K, V> m) {
System.out.printf("%s -> %s\n", k, m.get(k));
}
}