The Autoboxing example imo is a case of "Java isn't so fast". Why can't this be optimized behind the scenes by the compiler ?
Rest of advice is great: things compilers can't really catch but a good code reviewer should point out.
Rest of advice is great: things compilers can't really catch but a good code reviewer should point out.
Long sum = 0L;
for (Long value : values) {
sum += value;
}
I also want to highlight that there are plenty of collections utilizing primitive types. They're not generic but they do the job, so if you have a bottleneck, you can solve it.That said, TBH I think that adding autoboxing to the language was an error. It makes bad code look too innocent. Without autoboxing, this code would look like a mess and probably would have been caught earlier.
But that's the thing, in other languages you don't need a workaround to work on primitives directly.