'This' type

Marek Kozieł develop4lasu at gmail.com
Tue Mar 3 13:18:49 PST 2009


W dniu 3 marca 2009 21:55 użytkownik Neal Gafter <neal at gafter.com> napisał:

> Not seeing a problem is not the same thing as demonstrating that no
> problem can occur.  One set of problems arise when you use "This" in a
> superclass type argument, as you did in an example.  I simply don't
> know what subtype relationships that creates.
>
> interface A extends Collection<This> {}
>
> After this, is A a subtype of Collection<A>?
>
> On Tue, Mar 3, 2009 at 12:40 PM, Marek Kozieł <develop4lasu at gmail.com>
> wrote:
> > If we think about it onlt as extension for return types it's quite easy.
> >
> > interface IA{ This method(); }
> >
> > interface IB extends IA { }
> > now:
> >
> > static void some(IB x){
> >
> > __ x.method() : return type is IB as This for IB;
> >
> > __ ((IA)x).method() : return type is visible as IA as This for IA;
> >
> > }
> > If u have some doubts, just mail the sample (I do not see any reason for
> > valid code to make ClassCastExceptions to appear).
> >
> > --
> > Pozdrowionka. / Regards.
> > Lasu aka Marek Kozieł
> >
> > http://lasu2string.blogspot.com/
> >
> >
>

Oh.

I get it now.

Yes A is a subtype of Collection<A>

but after

B extends A

B will be Collection<B> from B point of view

B will be Collection<A> from A point of view

In base relation is same as one created by overloaded methods.

-- 
Pozdrowionka. / Regards.
Lasu aka Marek Kozieł

http://lasu2string.blogspot.com/



More information about the coin-dev mailing list