generic Map question

K

Koen

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
 
I

Ingo R. Homann

Hi,
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?

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
 
K

Koen

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

Koen
 
I

Ingo R. Homann

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top