4 ms·
The problem is rather that Java doesn't have generics and structs, so you're kind of forced to box things or can't use collections.
by carlmr 7mo ago
The problem is rather that Java doesn't have generics and structs, so you're kind of forced to box things or can't use collections.
- vbezhenar 7mo agoNo, in the example they provided, programmer wrote obviously stupid code. It has nothing to do with necessity: 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.
- carlmr 6mo ago>They're not generic but they do the job, so if you have a bottleneck, you can solve it. But that's the thing, in other languages you don't need a workaround to work on primitives directly.