Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / May 2006

Tip: Looking for answers? Try searching our database.

generic Map question

Thread view: 
Koen - 10 May 2006 14:57 GMT
I have this Map

private Map<Class<? extends IBusinessRule>, Collection<? extends
IBusinessRule>> businessRules;

where IBusinessRule is an interface, but what I actually want is
something like this

private <T extends IBusinessRule> Map<Class<T>, Collection<T>>
businessRules;

This is a map from the Class of an object to a Collection of objects
with exactly that type.

Is this possible? I can not figure out how to do that.

Koen
Ingo R. Homann - 10 May 2006 15:05 GMT
Hi,

> I have this Map
>
[quoted text clipped - 11 lines]
>
> Is this possible?

Yes, it is. But T has to be defined in the class or method:

class X<T extends IBusinessRule> {
  private Map<Class<T>, Collection<T>> businessRules;
}

or

class X {
  public <T extends IBusinessRule> void foo(Map<Class<T>,
                          Collection<T>> businessRules) {
   ...
   }
}

Hth,
Ingo
Koen - 10 May 2006 15:16 GMT
Ok, I understand, but I forgot to mention that this map businessRules is
a static field...

Koen

> Hi,
>
[quoted text clipped - 31 lines]
> Hth,
> Ingo
Ingo R. Homann - 10 May 2006 15:36 GMT
Hi,

> Ok, I understand, but I forgot to mention that this map businessRules is
> a static field...

Then, it is impossible. If it where possible - how/where would you like
to define it? (The fact that you cannot answer this question is the
reason why it is impossible! :-)

Ciao,
Ingo


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.