On 03/04/2014 02:41 AM, Jeroen Frijters wrote:
Brian Goetz wrote:
Embedded in this proposal is the desire to not provide a full-blown
"lvalue" form for variables; supporting any form of pass-by-reference at
the language level is a super-non-goal here.
Why is this? It solves these problems in an extremely clean way and also
provides lots of other value (for example, for JEP 191: Foreign Function
Interface).
I understand pass-by-reference is an expensive feature, but IMNSHO poluting
Java with this proposal will prove to be more expensive in the long run. It's
like erased generics all over again.
The expensive version of pass-by-reference is already supported
using java.lang.reflect.Field. You can think of .volatile as
a version of such mechanics that only works within the
context of a single expression, not across method calls.
There is plenty of precedent for this. For example you
cannot emulate the "+=" operator as a standalone method without
resorting to reflection. You can view this JEP as an extension
mechanism for safely adding similar l-value-based operators. (Although
only the JDK can implement these extensions.)
-Doug