作者NullLife (哀莫大於心死)
看板java
标题[问题] 写method泛型时,遇到一个问题
时间Thu Oct 31 16:27:39 2013
public <ListType extends List<MapType>
,MapType extends Map<?, ?>>
void sort(ListType targetList) {
// 内容
}
上面这个method可以正常使用
List<Map<String, String>> targetList = new ArrayList<Map<String, String>>();
sort(targetList);
但我想把Map的key跟value的型态也拿出来,就不行了...
public <ListType extends List<MapType>
,MapType extends Map<KeyType, ValueType>
,KeyType
,ValueType>
void sort(ListType targetList) {
// 内容
}
List<Map<String, String>> targetList = new ArrayList<Map<String, String>>();
sort(targetList);
上面这样要塞入targetList就出现错误...
Bound mismatch:
The generic method sort(ListType) of type ListMapSort
is not applicable for the arguments (List<Map<String,String>>).
The inferred type Map<String,String> is not a valid substitute
for the bounded parameter <MapType extends Map<KeyType,ValueType>>
因为我有需求在内容里使用key的type,但一直卡住...
想请问需要怎麽改?
或者是我哪里观念有误?
烦请指点,感恩。
--
我们全心全意的爱你 我们全心全意的爱你
亲像爱自己的母亲 亲像爱自己的母亲
不是你的土地特别香 不是你的物产特别丰富
929 吴志宁
因为你的怀抱这麽温暖 因为你用艰苦的奶 养大了我们
全心全意爱你
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 111.250.72.112