3 ms·
I think if it avoids having to repeat the type then type inference helps. And especially that last Java example, there I feel it is useful: for (var x : s
by hibbelig 7y ago
I think if it avoids having to repeat the type then type inference helps. And especially that last Java example, there I feel it is useful:
for (var x : someMap.entrySet()) {
String key = x.getKey();
Entity value = x.getValue();
...
}
Here, the reader just needs look at the next two lines to understand the type of x. In the article, the key and value types were long and complicated, and they asked us to refactor. But in the above example, the types are very simple, yet still it's better than
for (Map.Entry<String, Entity> x : someMap.entrySet()) {
String key = x.getKey();
Entity value = x.getValue();
...
}
I feel in this example, the type in front of x doesn't help me, as a reader.