Value-Based Classes vs Value Types
Brian Goetz
brian.goetz at oracle.com
Sun Feb 15 18:16:55 UTC 2015
> The State of the Values from 04/2014 [1] says "In fact, it seems
> likely that the boxed form of every value type will be a value-based
> class." If I understand this correctly, it's like we're implementing
> 'Integer' now, waiting for 'int' to be implementable in a couple of
> years.
That's a good mental model. We can't write 'int' yet, but we can design
its API, and if we are careful, we may be rewarded with better
performance in the future.
> Or is it more like we are already writing the value types, waiting for
> the language to catch up so we can then add the right qualifiers and
> effectively transform value-based classes into value types?
I don't think this is as good a model. Right now, one has to be quite
careful to not make identity-centric assumptions. Value-based classes
have other advantages besides their possible migration to values (e.g.,
the many benefits of immutability) but value types is definitely "give
up something to get something", where that something is our reliance on
identity and its consequences.
More information about the valhalla-dev
mailing list