|
|
|
|
|
by bluejekyll
1903 days ago
|
|
Perhaps this example will make it more obvious: boolean truthy = false;
truthy = null; // compilation failure, type mismatch
vs. the Boolean type Boolean truthy = new Boolean(false);
truthy = null; // compiles just fine
The reason Boolean (and other boxed primitive types) exist is because it is an Object (a reference type) and that allows them to be used in things like collections that expect Objects and not primitive types.Looking at https://openjdk.java.net/jeps/401 it's not totally clear to me at the moment how you can use ValueTypes (primitive keyword) in Collections. Might be that you'll need to take a reference to them with Type.ref (but I need to read 401 in more detail to understand that). Hope that helps. |
|
JEP 401 won't cover it quite yet, note this from the "Non Goals" section:
> An important followup effort, not covered by these JEPs, will enhance the JVM to specialize generic classes and bytecode for different primitive value type layouts.
It wasn't until recently that I understood for myself just how large the surface area of the "value types" problem is - it will be delivered incrementally. JEP 401 and 402 are the first steps (if I were to guess they will show up as previews soon? maybe JDK 17 or 18?), but there is more to come.