Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #12234

Re: Hairy generics question

From Lew <noone@lewscanon.com>
Newsgroups comp.lang.java.programmer
Subject Re: Hairy generics question
Date 2012-02-21 09:24 -0800
Organization albasani.net
Message-ID <ji0jvt$lig$1@news.albasani.net> (permalink)
References <3c65271e-a388-49c9-bcc6-ca3bf274e74f@e27g2000vbu.googlegroups.com>

Show all headers | View raw


On 02/21/2012 06:30 AM, sclaflin wrote:
> I have a number of sets of matched parameterized classes: a bean, a
> presenter, and a view.
> The presenters and views have parallel inheritance hierarchies (where
> T is the bean type, P the presenter type, and V is the view type):
>
> public class CompA extends CompItem<AInfo, CompA, CompAView>
> public class CompB extends CompItem<BInfo, CompB, CompBView>
>
> public class CompAView extends CompItemView<AInfo, CompA, CompAView>
> public class CompBView extends CompItemView<BInfo, CompB, CompBView>
>
> public class CompItemView<T extends CompItemInfo,
>                               P extends AbstractCompItem<T, P, V>,
>                               V  extends CompItemViewInterface<T, P,
> V>>
>    extends AbstractCompItemView<T, P, V>
>    implements CompItemViewInterface<T, P, V>
>
> public abstract class CompItem<T extends CompItemInfo,
>                                    P extends AbstractCompItem<T, P, V>,
>                                    V extends CompItemViewInterface<T,
> P, V>>
>    extends AbstractCompItem<T, P, V>
>    implements CompWidget<T>
>
> Many of the views are the same, so I wanted to just use the base view
> class instead of creating a separate view class for each presenter.
> So I tried:
>
> public class CompA extends CompItem<AInfo, CompA, CompItemView>
>
> But I get an error that says "The type CompItemView is not a valid
> substitute for the bounded parameter<V extends
> CompItemViewInterface<T,P,V>>  of the type CompItem<T,P,V>.
> Why can I use a class that extends CompItemView for the V type, and
> not CompItemView itself?

Your generics assertions have 'P' extend an 'AbstractCompItem' that depends on 
'P'. This type of generics circularity has a place, but it's often the result 
of confusion also. Which is it for you? Why does 'P' extend its own type? 
(Similarly for 'V'.)

As for covariance, you need to study the generics tutorial
<http://docs.oracle.com/javase/tutorial/extra/generics/index.html>
and Angelika Langer's site.

The combination is likely what's killing you. Remember that 'Foo extends Bar' 
does not imply (cannot imply) that 'Baz<Foo> extends Baz<Bar>'.

If you remove the circularity - if feasible, but please do explain why it's 
there at all - and do your covariance correctly your problem should vanish. I 
think perhaps you've overcomplicated your generics.

-- 
Lew
Honi soit qui mal y pense.
http://upload.wikimedia.org/wikipedia/commons/c/cf/Friz.jpg

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Hairy generics question sclaflin <steve@steveclaflin.com> - 2012-02-21 06:30 -0800
  Re: Hairy generics question Lew <noone@lewscanon.com> - 2012-02-21 09:24 -0800
  Re: Hairy generics question Roedy Green <see_website@mindprod.com.invalid> - 2012-02-21 11:05 -0800
    Re: Hairy generics question Lew <noone@lewscanon.com> - 2012-02-21 12:09 -0800
  Re: Hairy generics question Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2012-02-21 18:04 -0800
    Re: Hairy generics question Lew <noone@lewscanon.com> - 2012-02-21 18:31 -0800
    Re: Hairy generics question Steven Simpson <ss@domain.invalid> - 2012-02-22 08:31 +0000
  Re: Hairy generics question sclaflin@webucator.com - 2012-02-24 11:12 -0800
    Re: Hairy generics question Lew <noone@lewscanon.com> - 2012-02-24 12:03 -0800
      Re: Hairy generics question sclaflin@webucator.com - 2012-02-24 14:07 -0800
        Re: Hairy generics question Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2012-02-24 15:36 -0800
          Re: Hairy generics question sclaflin@webucator.com - 2012-02-25 10:27 -0800
          Re: Hairy generics question Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2012-02-26 13:13 -0400
            What is Model View Presenter. (Was: Hairy generics question) Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2012-02-26 10:22 -0800
              Re: What is Model View Presenter. (Was: Hairy generics question) Lew <noone@lewscanon.com> - 2012-02-26 13:08 -0800
                Re: What is Model View Presenter. (Was: Hairy generics question) Arne Vajhøj <arne@vajhoej.dk> - 2012-02-26 18:17 -0500
                Re: What is Model View Presenter. (Was: Hairy generics question) sclaflin@webucator.com - 2012-02-28 06:22 -0800
            Re: Hairy generics question Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2012-02-28 09:46 -0800
              Re: Hairy generics question Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2012-02-28 09:49 -0800
              Re: Hairy generics question Lew <noone@lewscanon.com> - 2012-02-28 12:45 -0800
              Re: Hairy generics question Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2012-02-29 19:37 -0400
                Re: Hairy generics question Lew <noone@lewscanon.com> - 2012-02-29 22:32 -0800

csiph-web