You cannot cast it like that. Create a new one:
List<A> listA = new ArrayList<A>(listB);
The constructor takes Collection<? extends A>
. It will point to the same references anyway.
More Related Contents:
- How do you cast a List of supertypes to a List of subtypes?
- How to have Java method return generic list of any type?
- Is List a subclass of List? Why are Java generics not implicitly polymorphic?
- Most efficient way to cast List to List
- Why do we assign a parent reference to the child object in Java?
- Why we can’t do List mylist = ArrayList(); [duplicate]
- Java Class.cast() vs. cast operator
- Can’t cast to to unspecific nested type with generics
- Cast Object to Generic Type for returning
- How to cast List to List
- List
- How to cast from List to double[] in Java?
- Cannot convert from List to List
- Casting to generic type in Java doesn’t raise ClassCastException?
- Create a List of primitive int?
- new ArrayList() failing in Java
- Java casting “.class”-operator used on a generic type, e.g. List, to “Class
- What’s the difference between unbounded wildcard type List and raw type List?
- ClassCastException vs. “cannot cast” compilation error
- Casting variables in Java
- At runtime, find all classes in a Java application that extend a base class
- What is the difference between Set and List?
- Generic array creation error
- Why won’t this generic java code compile?
- Difference between generic type and wildcard type
- How to create a custom deserializer in Jackson for a generic type?
- Hiding Fields in Java Inheritance
- Type safety: Unchecked cast from Object
- Is LinkedList thread-safe when I’m accessing it with offer and poll exclusively?
- Java generics, Unbound wildcards vs