Map<V, Set><V>> not a supertype of HashMap<V, HashSet><V>> ?

Hi,

I am relatively new to generics, so maybe my questions is dumb, if so please bear with me ... I have asked colleagues, but we're clueless.

I have the following code:

publicabstractclass myAbstractClass<T>{

publicabstract Set<T> getNewSet();

publicabstract Map<T, Set><T>> getNewMap();

}

publicclass myClass<T>extends myAbstractClass<T>{

public Set<T> getNewSet(){

returnnew HashSet<T>();

}

public Map<T, Set><T>> getNewMap(){

returnnew HashMap(T, HashSet<T>);

}

}

Everything works fine forgetNewSet(), but forgetNewMap() the compiler gives the error:Type mismatch: cannot convert from HashMap<V,HashSet><V>> to Map<V,Set>. I don't understand why...

The only solution I could find, thanks to a codeveloper's advice is:

publicclass myClass<T>extends myAbstractClass<T>{

public Set<T> getNewSet(){

returnnew HashSet<T>();

}

public Map<T, Set><T>> getNewMap(){

returnnew HashMap(T, Set<T>);

}

}

Furthermore, if I modify my second class as follows:

publicclass myClass<T>extends myAbstractClass<T>{

public Set<T> getNewSet(){

returnnew HashSet<T>();

}

public Map<T, Set><T>> getNewMap(){

returnnew HashMap(T, HashSet<T>);

}

public Map<T, Set><T>> getAnotherNewMap(){

returnnew HashMap(T, HashSet<T>);

}

}

Then I get the same compiler error forgetAnotherNewMap()... I'm definitely lost.

[3575 byte] By [ngirauda] at [2007-11-27 5:48:55]
# 1

import java.util.*;

public abstract class myAbstractClass < T > {

public abstract Set < T > getNewSet();

public abstract Map < T, ? extends Set < T > > getNewMap();

}

import java.util.*;

public class myClass < T > extends myAbstractClass < T > {

public Set < T > getNewSet() {

return new HashSet < T > ();

}

public Map < T, ? extends Set < T > > getNewMap() {

return new HashMap < T, HashSet < T > >();

}

}

Hippolytea at 2007-7-12 15:34:49 > top of Java-index,Java Essentials,Java Programming...
# 2
Wow, that was a *quick* answer :)Thanks a lot anyway, it solves my problem.
ngirauda at 2007-7-12 15:34:49 > top of Java-index,Java Essentials,Java Programming...
# 3
> Wow, that was a *quick* answer :)It would have been faster, but there is a big discussion going on inmy office about Miss Universe. Miss Brazil was my choice...
Hippolytea at 2007-7-12 15:34:49 > top of Java-index,Java Essentials,Java Programming...
# 4
> It would have been faster, but there is a big discussion going on in> my office about Miss Universe. Miss Brazil was my choice...It's too bad that Miss Romulus got caught in that time-space continuum tailback in the Zeta Quadrant and missed the competition.
DrClapa at 2007-7-12 15:34:49 > top of Java-index,Java Essentials,Java Programming...
# 5

> > It would have been faster, but there is a big

> discussion going on in

> > my office about Miss Universe. Miss Brazil was my

> choice...

>

> It's too bad that Miss Romulus got caught in that

> time-space continuum tailback in the Zeta Quadrant

> and missed the competition.

I would sign up for the pay-per-view if the could guarantee that the show

would be hijacked and the contestants enslaved by the Borg Collective.

Hippolytea at 2007-7-12 15:34:49 > top of Java-index,Java Essentials,Java Programming...