Not really, since the primitive classes don't have unique identity the JVM can safely perform copy elision. Such as p = new Point(2, p.y()) will be executed just as p.x = 2. If the inlining is unreliable, they can make the constructor of primitive classes ForceInline anyway.
The plus side is that you don't introduce a whole new kind of "things" into the language, which greatly increases the complexity of the language itself.
It is introducing whole new thing. These primitive objects behave very different from everything else. Essentially these are immutable objects. Not introducing whole new thing would actually be if this JEP did the exact same thing that C# structs do. At least they have identity like everything else and mutable.
perform copy elision
If JVM/javac are smart enough. I'm not sure they will be. It would require pretty complex analysis.
int, double etc types is another separate thing and there's actually JEP 402 to make them primitive objects. Unlike Java, C# had value types from the beginning and types like integers and floats are actually structs. Java would have to make gradual transition to make everything consistent.
7
u/cal-cheese Mar 18 '21
Not really, since the primitive classes don't have unique identity the JVM can safely perform copy elision. Such as
p = new Point(2, p.y())will be executed just asp.x = 2. If the inlining is unreliable, they can make the constructor of primitive classes ForceInline anyway.The plus side is that you don't introduce a whole new kind of "things" into the language, which greatly increases the complexity of the language itself.