PROPOSAL: Return 'this'
Thomas.Hawtin at Sun.COM
Thu Mar 26 08:03:53 PDT 2009
Marek Kozieł wrote:
> MAJOR ADVANTAGE:
> Simplification of “return this” statement.
> 'void' can be easy replaced with 'this'.
> MAJOR BENEFIT(s): It would prevent NullPointerException, and make some
> 'builder' like interfaces look really clear and simple.
My problem with this is that it is an attempt to fix a hack due to a
language problem with a language hack.
The underlying problem is that Java does not have a concise syntax for
builders. The usual hack is for builders to return this and clients to
use method chaining. This solution makes the hack easier. A better
solution would be direct, explicit support for builders in some form.
Also the variant of this proposal that client-side reinterprets
returning void to return this, would interfere to some extent with
covariantly returning void when overriding a return of Void.
More information about the coin-dev