Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Mutually dependent generic abstract classes

 
Lorenz Fischer
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,

Maybe someone in here gets this generics topic thoroughly Even though I thought I did, I obviously don't :-/

Ok, here's the story:
I have two abstract classes that link to each other. I'd like to use generic types, so I can define some of the methods in my abstract classes while still having type safety when calling them from the subclasses. I tried it many ways, but I'm unable to write the code below without having either warnings about type safety, usage of raw types, or bound mismatch compilation errors.

Any help would be greatly appreciated :-)



Cheers
Lorenz
[ January 04, 2008: Message edited by: Lorenz Fischer ]
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem is that a class declared as

class MyItem extends Item<Bid<MyOtherItem>>

would be syntactically legal, but lead to problems.
 
Bill Shirley
Ranch Hand
Posts: 457
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The infinite recursion looks to be a problem for this new language feature.

I think you will have to pick one of the two types to genericize.
 
Lorenz Fischer
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Ilja and Bill for your answers,

I tried it another way now. In the new code there can be no misunderstanding for the compiler, since one has to specify both (MyItem and MyBid) at the same time. But now I get an error stating that:

The method setItem(I) in Type Bid<I,B> is not applicable for the arguments (Item<I,B>

I don't understand this, since "I" in my case is defined as "something" that "extends Item<I,B>", which is what I'm trying to pass as the method argument. Do you spot the mistake?



Thank you very much for your time!
[ January 08, 2008: Message edited by: Lorenz Fischer ]
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic