cast a List to a Collection

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);

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)