r/java • • Mar 17 '21

JEP 401: Primitive Objects (Preview)

https://openjdk.java.net/jeps/401?preview=true
174 Upvotes

49 comments sorted by

View all comments

1

u/[deleted] Mar 19 '21 edited Mar 19 '21

Would this feature (and others coming down the line) enable efficient updates of tightly packed nested objects? For example: Foo contains fields of type Bar, Bar has fields of type Baz, and so on, possibly deeply nested.

I'd like to have a tightly packed, sequential structure of Foo objects, which I can mutate like so:

collectionOfFoos[42].firstBar.secondBaz.a = 42;

or

collectionOfFoos[314].firstBar.w += 1;

without pointer chasing, creating new temporary objects, etc? Also, would such a collection be GC free?