Return 'this' proposal
Joseph D. Darcy
Joe.Darcy at Sun.COM
Tue Mar 17 14:07:08 PDT 2009
This 'this' proposal remains vague and imprecise.
Including this type/self type in a language is a continuing area of
study; for example, see the recent paper
"Matching ThisType to Subtyping," Chieri Saito and Atsushi Igarashi,
Kyoto University, Japan, ACM SAC 2009.
There are open bugs requesting this capability. For example typing
"site:bugs.sun.com this type" into a popular search engine quickly
yields, amongst other hits,
6479372 Add self types (type of 'this' aka ThisClass) to the language
This bug discusses the size of the type system impact of this change, a
magnitude far too large for Project Coin.
There is no need to submit further refinements of this idea; any
proposal along the lines of adding a this type will be out of scope for
Project Coin.
-Joe
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
>
>
More information about the coin-dev
mailing list