You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@wicket.apache.org by Martin Makundi <ma...@koodaripalvelut.com> on 2011/08/30 03:52:50 UTC

Self type

Hi!

Is wicket using self type yet for methods like add(cc) {...; return this; } ?

http://calliopesounds.blogspot.com/2010/11/having-java-generic-class-return-type.html

**
Martin

Re: Self type

Posted by Igor Vaynberg <ig...@gmail.com>.
this is not going to work for wicket because this system of
self-typing does not support anonymous classes

eg given:

Component<S extends Component<S>>
MarkupContainer<S extends MarkupContainer<S>> extends Component<S>
WebMarkupContainer<S extends WebMarkupContainer<S>> extends MarkupContainer<S>

you can no longer create an anonymous subclass of WebMarkupContainer or

WebMarkupContainer<?> w=new WebMarkupContainer<WHAT_GOES_HERE>("w") {  }

this style of coding is very common and is essential to wicket.

-igor




On Mon, Aug 29, 2011 at 6:52 PM, Martin Makundi
<ma...@koodaripalvelut.com> wrote:
> Hi!
>
> Is wicket using self type yet for methods like add(cc) {...; return this; } ?
>
> http://calliopesounds.blogspot.com/2010/11/having-java-generic-class-return-type.html
>
> **
> Martin
>

Re: Self type

Posted by tetsuo <ro...@gmail.com>.
I've used this technique in some projects (internal APIs), with some degree
of success, but I don't think it fits well in this case.
Java's generics doesn't support this very well. It makes the code too
verbose, and in some inheritance cases, it just doesn't work.



One feature I would love to see in Java (although I have no hope to ever
have it) is something like this:

class A {
  public this add(Component c) {
    if (c == null)
      return; // 'this' is implicit, just like 'void'
    components.add(c);
    // 'return this;' is implicit, just like 'void'
  }
}

class B extends A {}

A a = new A().add(comp);
B b = new B().add(comp); //since 'this' is always implicit (so, cannot be
overridden), the compiler would know that the return type is B, not A


method chaining paradise! :)



On Mon, Aug 29, 2011 at 11:11 PM, richard emberson <
richard.emberson@gmail.com> wrote:

> For many months the Scala port of Wicket 1.5 has used self type
> return values (this.type) where appropriate; more than 10 methods
> in Component, more than 5 in MarkupContainer, etc. with all
> tests passing and some code simplification (or, at least, the
> removal of some casts). Ought to work in Java also.
>
> Richard
>
>
> On 08/29/2011 06:52 PM, Martin Makundi wrote:
>
>> Hi!
>>
>> Is wicket using self type yet for methods like add(cc) {...; return this;
>> } ?
>>
>> http://calliopesounds.**blogspot.com/2010/11/having-**
>> java-generic-class-return-**type.html<http://calliopesounds.blogspot.com/2010/11/having-java-generic-class-return-type.html>
>>
>> **
>> Martin
>>
>>
> --
> Quis custodiet ipsos custodes
>

Re: Self type

Posted by Martin Makundi <ma...@koodaripalvelut.com>.
Oh, java 7 is nicer?

http://blog.joda.org/2007/08/java-7-self-types_1953.html

2011/8/30 richard emberson <ri...@gmail.com>:
> For many months the Scala port of Wicket 1.5 has used self type
> return values (this.type) where appropriate; more than 10 methods
> in Component, more than 5 in MarkupContainer, etc. with all
> tests passing and some code simplification (or, at least, the
> removal of some casts). Ought to work in Java also.
>
> Richard
>
> On 08/29/2011 06:52 PM, Martin Makundi wrote:
>>
>> Hi!
>>
>> Is wicket using self type yet for methods like add(cc) {...; return this;
>> } ?
>>
>>
>> http://calliopesounds.blogspot.com/2010/11/having-java-generic-class-return-type.html
>>
>> **
>> Martin
>>
>
> --
> Quis custodiet ipsos custodes
>

Re: Self type

Posted by richard emberson <ri...@gmail.com>.
For many months the Scala port of Wicket 1.5 has used self type
return values (this.type) where appropriate; more than 10 methods
in Component, more than 5 in MarkupContainer, etc. with all
tests passing and some code simplification (or, at least, the
removal of some casts). Ought to work in Java also.

Richard

On 08/29/2011 06:52 PM, Martin Makundi wrote:
> Hi!
>
> Is wicket using self type yet for methods like add(cc) {...; return this; } ?
>
> http://calliopesounds.blogspot.com/2010/11/having-java-generic-class-return-type.html
>
> **
> Martin
>

-- 
Quis custodiet ipsos custodes