I called a getElements
method which returns Iterable<Element>
.
I did this:
List<Element> elements = (List<Element>) getElements();
This generates the error:
java.lang.ClassCastException: com.utesy.Element$3
cannot be cast to java.util.List
I thought a List
was a type of Iterable
?
getElements();
method – DepurativeList
interface extends theIterable
interface - so yes,List
is of typeIterable
, as you say. But that doesn't mean that whateverIterable
is returned bygetElements
is also aList
. All Lists are Iterables, but not all Iterables are Lists. – Arbutus