Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Why should compiler optimize obviously dumb code? If developer wants to create billions of heap objects, compiler should respect him. Optimizing dumb code is what made C++ unbearable. When you write one code and compilers generates completely different code.


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.


No, 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.


>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.




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: