Return 'this' proposal

Reinier Zwitserloot reinier at zwitserloot.com
Sun Mar 15 14:52:18 PDT 2009


Marek,

the interesting/complicated part of a return this proposal is the  
actual return type (in the classfile) of the method. Should it be  
'void'? Should it be the type of the class? But, in that case, every  
method that has a return type of 'this' needs to be dummy-overridden  
in every subclass just to set the return type correctly.

You've covered none of this in your proposal.

  --Reinier Zwitserloot



On Mar 15, 2009, at 22:34, Marek Kozieł wrote:

> AUTHOR: Lasu aka Marek Kozieł
>
> GENESIS
>
> It's a simplified 'This' type problem, which seems to be too much
> complicated as for now and need more analyses. Construction is  
> designed not
> to interact with possibility that 'This' type will be introduced.
> OVERVIEW
>
> FEATURE SUMMARY:
> It allows the method to return 'this' object.
>
> MAJOR ADVANTAGE:
> Simplification of return this; statement.
> 'void' can be easy replaced with 'this'.
>
> MAJOR BENEFIT(s):It would prevent NFP, in a described situation, and  
> make
> some 'builder' like interfaces look really clear and simple.
>
> MAJOR DISADVANTAGE:
> It's a change in language. Depending on the way that it would be  
> compiled to
> byte-code, it determine compatibility(here may lie some problem that  
> I do
> not know about).
>
> ALTERNATIVES:
> Self-bounded generics.
>
>
> EXAMPLES
>
> SIMPLE/ADVANCED EXAMPLE:
> public class Builder
> {
>
>  public this add (char c){...}
>
>  public this add (String c){
>    if (c==null){
>      ...
>      return; // this will be returned
>    }
>    ...
>  }
>
>  public static void test(Builder builder) {
>    builder.add('.').add("test()").add(':');
>  }
>
> }
> DETAILS
>
> SPECIFICATION:
> JLS 8.4:
> http://java.sun.com/docs/books/jls/third_edition/html/classes.html#8.4
>
> ResultType:
>  Type
>  void
>  this
>
> A method declaration either specifies the type of value that the  
> method
> returns, uses the keyword void to indicate that the method does not  
> return a
> value, or uses the keyword this to indicate that the method return the
> reference to called object.
>
> Keyword this cannot occurs if method is static.
>
>
> JLS 14.17:
> http://java.sun.com/docs/books/jls/third_edition/html/statements.html#14.17
>
> ReturnStatement:
>  return Expressionopt ;
>
> A return statement with no Expression must be contained in the body  
> of a
> method that is declared, using the keyword void, not to return any  
> value
> (§8.4), or in the body of a method that is declared, using the  
> keyword this
> , to return this reference (§8...),or in the body of a constructor  
> (§8.8).
>
> COMPILATION:
> Returned 'void' should be replaced with 'this', no more no less.
>
> TESTING:
> Normal way.
>
> LIBRARY SUPPORT:
> No.
>
> REFLECTIVE APIS:
> No.
>
> OTHER CHANGES:
>
> I wander what object should represent 'this' return type in:
> Method.getReturnType(); (this.getObject() ?)
>
> MIGRATION:
> None.
>
> COMPATIBILITY
> Backward: full.
>
> REFERENCES
> Bug: 6479372: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6479372
> http://java.net/cs/user/view/cs_msg/37432
> Return 'this' proposal :
> http://lasu2string.blogspot.com/2009/03/return-this-proposal.html
>
> -- 
> Pozdrowionka. / Regards.
> Lasu aka Marek Kozieł
>
> http://lasu2string.blogspot.com/
>




More information about the coin-dev mailing list