On Tuesday, 5 May 2015 at 20:40:59 UTC, Luís Marques wrote:
Hi,
For a comparison with the Java language, I'm trying to come up
with some good examples of custom types that should be value
types (but that must be ref types in Java). I think the most
obvious ones are numeric types. So BigNum, MyNum, etc. are good
examples because programmers are used to numeric types being
value types, and having them suddenly become a ref type just
because it's MyNum instead of long is really annoying. Still,
could you come up with some type that would really benefit from
being a value type but that isn't numeric (or otherwise
similar)?
Thanks for your help!
Luís
To add to what others have said - whenever you think you will
benefit from stack-allocation. Read this article:
http://www.ibm.com/developerworks/library/j-jtp09275/
Java is good at escape analysis. But I find it really useful to
be able to specify a type that will always be allocated on the
stack (unless you really want it on the heap).