Hacker News new | past | comments | ask | show | jobs | submit login

I would love to have this in Java, hopefully this JEP makes it!



As would I. There are a ton of places where the JVM is defensively copying arrays. It often comes up (for me in my work) as a performance problem.

A real common example of this is `Enum#values`.

Ideally (IMO) this applies some aggressive COW operations. So perhaps internal to the enum you have a frozen array of the values and for "values()" you return something like `VALUES.unfreeze()` which points to a transparent unfrozen array. On a write action, you'd copy the array but in the general case you'd simply read from the frozen array until someone does something dumb.

You could take it a step further and simply expose the `values` field or add a new "frozenValues" method to not break existing code. In either case, you'd end up with faster performance because the JVM isn't copying the internal array needlessly.




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

Search: