[英]When using ArrayList(Collection<? extends E> c) for a copy constructor I get two errors
public ListArrayListBased(ListArrayListBased < E > var)
{
items = new ArrayList < E> (ArrayList(ListArrayListBased
< ? extends E > var));
}
Using this line of code gives me two errors.使用这行代码给了我两个错误。
I was able to fix the second one by putting :: after ListArrayListBased but I have no clue what that did or how it worked.我能够通过在 ListArrayListBased 之后放置 :: 来修复第二个,但我不知道它做了什么或它是如何工作的。 I am looking more for an explanation on the errors then on the solutions to the problem.
我正在寻找更多关于错误的解释,然后是问题的解决方案。 Thanks!
谢谢!
This is a copy constructor, and you're trying to assign the items
member variable, which is presumably the list inside your class.这是一个复制构造函数,您正在尝试分配
items
成员变量,这可能是您的类中的列表。
So, copy the items
list from var
:因此,从
var
复制items
列表:
items = new ArrayList<>(var.items);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.