出什么问题了
private Map<List<K>, V> multiMap= new HashMap<ArrayList<K>,V>();
Run Code Online (Sandbox Code Playgroud)
编者说它Type mismatch: cannot convert from HashMap<ArrayList<K>,V> to Map<List<K>,V>.我是否必须提供特定类别的列表?为什么?
Phi*_*ler 14
你必须写
private Map<List<K>, V> multiMap= new HashMap<List<K>,V>();
Run Code Online (Sandbox Code Playgroud)
通用参数的值必须在两侧完全匹配(只要您不使用通配符).原因是Java Generics没有对立/协方差(HashMap<List>不是超类型HashMap<ArrayList>,虽然List当然是超类型ArrayList).
| 归档时间: |
|
| 查看次数: |
2267 次 |
| 最近记录: |