When using ArrayList(Collection<? extends E> c) for a copy constructor I get two errors

164 Views Asked by At
public ListArrayListBased(ListArrayListBased < E > var) 

{

items = new ArrayList < E> (ArrayList(ListArrayListBased 
        < ? extends E > var));

}

Using this line of code gives me two errors.

  1. Wildcard is not allowed at this location.
  2. Syntax Error on token "ListArrayListBased", :: expected after token.

I was able to fix the second one by putting :: after ListArrayListBased but I have no clue what that did or how it worked. I am looking more for an explanation on the errors then on the solutions to the problem. Thanks!

1

There are 1 best solutions below

0
Andy Turner On

This is a copy constructor, and you're trying to assign the items member variable, which is presumably the list inside your class.

So, copy the items list from var:

items = new ArrayList<>(var.items);