- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
Java 集合中 addAll(..) 方法的正确参数类型是什么?如果我这样做:
List<? extends Map<String, Object[]>> currentList = new ArrayList<Map<String, Object[]>>();
Collection<HashMap<String, Object[]>> addAll = new ArrayList<HashMap<String, Object[]>>();
// add some hashmaps to the list..
currentList.addAll(addAll);
我知道我需要初始化这两个变量。但是,我收到一个编译错误(来自 eclipse):
Multiple markers at this line
- The method addAll(Collection<? extends capture#1-of ? extends Map<String,Object[]>>) in the type List<capture#1-of ? extends Map<String,Object[]>> is not applicable for the arguments (List<capture#2-of ? extends
Map<String,Object[]>>)
- The method addAll(Collection<? extends capture#1-of ? extends Map<String,Object[]>>) in the type List<capture#1-of ? extends Map<String,Object[]>> is not applicable for the arguments
(Collection<HashMap<String,Object[]>>)
我做错了什么?
最佳答案
替换extends
通过 super
.
addAll()
本身需要一个 ? extends T
参数,当 T
时那将不起作用是? extends Map<K, V>
.随着变化,它将变得有效 ? extends ? super Map<K, V>
.
但是,最好还是删除那个 ? extends
(或 ? super
)。在这种特殊情况下这是多余的。只需使用 List<Map<String, Object[]>>
. addAll()
然后将有效地采取 ? extends Map<String, Object[]>>
.
关于Java 泛型和 addAll 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2701630/
Java API docs say以下关于Collections.addAll The behavior of this convenience method is identical to that
我的代码没有编译,我不太清楚为什么。这是代码: ArrayList classifications = productData .stream()
我对此有点困惑,所以希望能提供一些说明。 public void addAll(List animals) 对比 public void addAll(List animals) 最佳答案 区别在于
每当调用 Collection#addAll 时,它都会创建参数列表的副本,然后将其附加到调用 addAll 的集合。 下面是案例一的代码: if (parentData != 0)
对不起标题,但我不知道如何更好地解释它! 假设我在 Java 中有这个类: public class ToyClass { public int number; } 还有一个名为 ToyCla
我必须将 PaginatedQueryList 添加到来自 dynamoDbMapper.query 的 secondList 以进行测试。我怎样才能实现它? List exampleList = s
如果尝试向阻塞队列添加超过阻塞队列剩余大小的集合,会发生什么?从我目前阅读的文档中并不清楚这一点。 LinkedBlockingQueue foo = new LinkedBlockingQ
在一个方法中,我进行了两次调用。第一个调用从另一个方法构造并返回一个哈希集。第二次调用将这个新构造的集合添加到现有集合中,并作为参数传递给此方法。 public static void someMet
所以我的目标是用从 1 到 x 部分的 y 个随机数填充 arraty,然后计算每个数字重复的次数并打印它。这是代码: int counter = 1; int length = random
我目前正在学习泛型,我有一个任务,我必须创建一个带有 T 类型参数和数组数据成员以及一些方法(setItem、getItem、visitor、condition 和 addAll)的 Array 类。
我正在尝试制作一个创建棋盘的 javafx 程序。但是,当我尝试运行我的程序时,它会在这一行中抛出异常:optionsPane.getChildren().addAll(optionsPane, n_
java.util.Collections 中 addAll 方法的实现只是循环遍历源集合,并为源集合中的每个元素调用接收集合的 add 方法。 因此,如果接收集合的容量很小并且我们要向其中添加许多元
下面的代码用于 ListView 的搜索过滤器。每次更改 tbSearch editText 中的文本时, ListView 中的项目也必须更改。执行进入 if 语句 (txt.length()==0
我正在尝试查找字符串中唯一字符的数量。解决方案必须尽可能高效(时间复杂度 O(N);非常大的数组;一般来说是大 O)。我决定这样做(如果您有更好的解决方案请告诉我)。唯一的问题是,当我尝试运行它时,它
Map> mapp = new HashMap>(); HashSet set1 = new HashSet(); set1.add("a"); HashSet set2 = new HashSet(
import java.util.*; public class MyClass { public static void main(String[] args) { List a = n
我刚刚开始接触 java 和 android。 下面是我的代码,用于在 Activity 中添加所有按钮然后隐藏它们。问题:无论如何,他们是否会自动添加 Activity 中的所有按钮,而不必列出每个
为什么我在执行以下代码时遇到异常。 String[] array1 = {"A","B","C","D","E"}; String[] array2 = {"F","G","H","I"};
如果我想将一个列表添加到另一个列表,我调用 target.adAll(source)。 但是如果我需要先处理列表中的每个值怎么办? 我可以做类似的事情 for(String s: source) {
最近在List.addAll中发现了一个使用流的代码片段,但是我看不出为什么要使用它。 所以给出一个简单的列表。 List subList作为参数传递给方法。有一个是另一个,它是一个字段并且包含相同类
我是一名优秀的程序员,十分优秀!