Java is pass-by-value. How could you modify the language to introduce passing by reference (or some equivalent behavior)?
Take for example something like
<
To answer your question:
Where can this fail?
thisnew...and possibly others. Basically, your ref keyword must only be usable if the parameter source is a non-final field or local variable. Any other source should generate a compilation error when used with ref.
An example of (1):
final String s = "final";
passByReference(ref s); // Should not be possible
An example of (2):
passByReference(ref this); // Definitely impossible
An example of (3):
passByReference(ref toString()); // Definitely impossible
passByReference(ref new String("foo")); // Definitely impossible
An example of (4):
passByReference(ref "literal"); // Definitely impossible
And then there are assignment expressions, which seem to me like something of a judgement call:
String s;
passByReference(ref (s="initial")); // Possible, but does it make sense?
It's also a little strange that your syntax requires the ref keyword for both the method definition and the method invocation. I think the method definition would be sufficient.