开发者

Bounded wilcard not working for List inserted in Map

开发者 https://www.devze.com 2023-04-10 19:03 出处:网络
The following code explains my problem: interface f1 {} interface f2 extends f1{} 1. List<? extends f1> l1 = new ArrayList<f2>();

The following code explains my problem:

interface f1 {}

interface f2 extends f1{}


1. List<? extends f1> l1 = new ArrayList<f2>();

2. Map<String, ? extends f1> m1 = new HashMap<String, f2>();

3. Map<String, List<? extends f1>> m2 = new Hash开发者_如何转开发Map<String, List<f2>>();

No. 1 and 2 work but no. 3 gives an error on eclipse. It says: Type mismatch: cannot convert from HashMap<String,List<f2>> to Map<String,List<? extends f1>> Could you please help me figure out why.


Use

Map<String, ? extends List<? extends f1>> m2 = new HashMap<String, List<f2>>();
0

精彩评论

暂无评论...
验证码 换一张
取 消