Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!news1.tnib.de!feed.news.tnib.de!news.tnib.de!newsfeed.freenet.ag!newsfeed.kamp.net!newsfeed.kamp.net!nx02.iad01.newshosting.com!newshosting.com!69.16.185.21.MISMATCH!npeer03.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!post01.iad.highwinds-media.com!newsfe20.iad.POSTED!83aa503d!not-for-mail From: Daniel Pitts User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:10.0.1) Gecko/20120208 Thunderbird/10.0.1 MIME-Version: 1.0 Newsgroups: comp.lang.java.programmer Subject: Re: Hairy generics question References: <3c65271e-a388-49c9-bcc6-ca3bf274e74f@e27g2000vbu.googlegroups.com> In-Reply-To: <3c65271e-a388-49c9-bcc6-ca3bf274e74f@e27g2000vbu.googlegroups.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Lines: 60 Message-ID: X-Complaints-To: abuse@newsrazor.net NNTP-Posting-Date: Wed, 22 Feb 2012 02:04:11 UTC Date: Tue, 21 Feb 2012 18:04:07 -0800 X-Received-Bytes: 3530 Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:12241 On 2/21/12 6: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 > public class CompB extends CompItem > > public class CompAView extends CompItemView > public class CompBView extends CompItemView > > public class CompItemView P extends AbstractCompItem, > V extends CompItemViewInterface V>> > extends AbstractCompItemView > implements CompItemViewInterface > > public abstract class CompItem P extends AbstractCompItem, > V extends CompItemViewInterface P, V>> > extends AbstractCompItem > implements CompWidget > > 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 > > But I get an error that says "The type CompItemView is not a valid > substitute for the bounded parameter CompItemViewInterface> of the type CompItem. > Why can I use a class that extends CompItemView for the V type, and > not CompItemView itself? I'll try to propose a way to fix your type declarations, but then I'll make a better suggestion, please read through ;-) I think what you'll need to do is have generic parameter to CompA: public class CompA, View>> extends CompItem, View> The better suggestion that I have for you is to try to find a better way of handling this generic-type interdependency. I once wrote something very similar, and it is a headache to maintain. Especially when I needed to add in (I'm making up names to match your example) CompItemAccessor. And then later CompItemValidator. And so on. I eventually ended up with one class ContentTypeMetadata which contained all the basic information for each content type, and the class types didn't really have to know much about each other. Ask yourself, do all these objects really need to know the exact type of all the other objects, or can they just know about some shared base interface?