PROPOSAL: Return 'this' (original) (raw)
Marek Kozieł develop4lasu at gmail.com
Thu Mar 26 08:51:46 PDT 2009
- Previous message: PROPOSAL: Return 'this'
- Next message: PROPOSAL: Return 'this'
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
2009/3/26 Tom Hawtin <Thomas.Hawtin at sun.com>:
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. Tom Hawtin
This is some point. I do not like it just because in need to be served outside, which increase interactions. Notice that this will work totally in unexpected way when:
we have a.jar & b.jar while both are compiled and b.jar use a.jar, than some one change (in a.jar ) interface A{ this some(); } to: interface A{ A some(); } because he want to return other object...
this would work in pretty unexpected way.
BTW. Did you wander if Interfaces / abstract classes should be final (with explicit declared classes/interfaces available for inheritance), like: final interface A allow Ab, Ac{...} this was my idea connected to inheritance security.
-- Pozdrowionka. / Regards. Lasu aka Marek Kozieł
http://lasu2string.blogspot.com/
- Previous message: PROPOSAL: Return 'this'
- Next message: PROPOSAL: Return 'this'
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]