cast a List to a Collection

collections, java, list

Solution

`List<T>` already implements `Collection<T>` - why would you need to create a new one?

Collection<T> collection = myList;

The error message is absolutely right - you can't directly instantiate an interface. If you want to create a copy of the existing list, you could use something like:

Collection<T> collection = new ArrayList<T>(myList);

Problem

i have some pb. I want to cast a List to Collection in java ``` Collection<T> collection = new Collection<T>(mylList); ``` but i have this error Can not instantiate the type Collection

Original source