2

I have a problem with initialize a list of hashset in java.

I tried List<Set<Character>> list = new ArrayList<HashSet<Character>>();
Then I got a error like: incompatible types: ArrayList<HashSet<Character>> cannot be converted to List<Set<Character>>.

However, List<HashSet<Character>> list = new ArrayList<HashSet<Character>>();works.

I am confused about it, because I can initialize a list of list by using:

List<List<Integer>> list = new ArrayList<List<Integer>>();

I thought the part in the lhs is just a interface or abstract class, so I thought List<Set<T>> would be ok...

Can someone explain it for me? Thanks!

0 Answers0