3 ms·
Does java have a decent story on value types now e.g can I make an ArrayList<long> and trust that it’s one array of longs on the heap and not an array of pointe
by alkonaut 5y ago
Does java have a decent story on value types now e.g can I make an ArrayList<long> and trust that it’s one array of longs on the heap and not an array of pointers to Longs?
This was what made me ragequit Java 10 years ago.
- bradleyjg 5y agoNo. You can’t make an ArrayList<long> at all. You can make an ArrayList<Long> and trust the JVM to optimize as it may or you can use c++.
- kjeetgill 5y agoYou can mostly trust the JVM to not optimize this the way you'd want for primitives. ValueTypes are int he works though, and using a supplementary library for primitive specialization like Trove or fastutil have become the norm for now. Not ideal, but tolerable!
- bradleyjg 5y agoIf your application needs that kind of control, use a more suitable, lower level language. If you just want that level of control for aesthetic reasons, get over yourself.
- kjeetgill 5y agoJava is that language though! It has primitives and primitive arrays and the language is built around many comfortable ways of using them compared to something "a bit more high level" like a python, javascript, or ruby; but you get to keep your compacting GC, chunky reflection, runtime introspection, compared to a C, C++ or rust. Primitives don't play well with the generics though, for decent enough reasons, so the standard library leaves out many conveniences that you can pull in as needed. Of course we're excited about them playing well together, but the sweet spot in the design space is still being worked out. We call that effort ValueTypes, lol. (well sorta. there's more to value types than just primitive specialization but i digress) I get that teasing jabs at java are always and fashion but consider that for many, it persists because it is a bit of a sweet-sport language. I think Go succeeds when it does for precisely the same reasons.
- bradleyjg 5y agoDon’t get me wrong, I like java and hate c++. I worry about the rapid pace of change post 8. Some of the changes seem great individually but trying to be everything to everyone is how you end up with c++.
- Twisol 5y agoNot yet. You can track Project Valhalla [0], the incubator for value/inline types in OpenJDK. But I don't get the sense it's landing particularly soon. https://openjdk.java.net/projects/valhalla/ https://openjdk.java.net/projects/valhalla/
- Skinney 5y agoReally? They’ve already written the JEPs. It seems to me that they just have a few more details to iron out. Wouldn’t be surprised to see something land for Java 19.
- kaba0 5y agoNot likely in 19 unfortunately. It is still lots of work with many many interactions with the whole of the language.
- Twisol 5y agoI'd definitely be curious about which signals you're drawing on. From what I've seen, the Valhalla OpenJDK wiki has gone without update for quite some time, and even that wiki refers to JEP 169 ("Value Objects") as old. I do get the feeling that there's activity, given that JEP 416 is targeted for Java 18 and specifically refers to Valhalla (and Loom) as benefactors of the proposal, and seeing as the mailing list is reasonably active. But since there's little official word and not much buzz on my radar (even Loom has significant buzz), I'm not expecting anything soon.
- Skinney 5y agoJEP 401 (candidate status) was updated this september: https://openjdk.java.net/jeps/401 https://openjdk.java.net/jeps/401 Also in September, a brief status was posted: https://mail.openjdk.java.net/pipermail/valhalla-spec-observers/2021-September/001575.html https://mail.openjdk.java.net/pipermail/valhalla-spec-observ...
- Twisol 5y ago
- silvestrov 5y agoThe FastUtil library is very good for this: https://fastutil.di.unimi.it https://fastutil.di.unimi.it