Clarification on migration to value types and boxed vs unboxed representations

John Rose john.r.rose at
Tue Jan 6 03:43:28 UTC 2015

On Jan 5, 2015, at 6:02 PM, Vitaly Davidovich <vitalyd at> wrote:
> Also, you can just as well get lost writes with immutable objects if you forget to reassign the variable with the result of a mutating operation.

The risks are in some sense complementary.  But IMO this one, unlike the aliasing problem, is easy to check for statically:

class ImmutableComplex { ...
   ImmutableComplex add(ImmutableComplex that) {
     return new ImmutableComplex( +, +;

class String { ...
  String concat(String str) { ... }

void dufus(String s) {
  s.concat(" more!");  // javac says Warning: discarding a preserved value
  return s;

— John

More information about the valhalla-dev mailing list