“Iterable cannot be cast to List” - Isn't `List` a type of `Iterable`?

后端 未结 10 1677
生来不讨喜
生来不讨喜 2021-02-20 00:27

I called a getElements method which returns Iterable.

I did this:

List elements = (List

        
10条回答
  •  长情又很酷
    2021-02-20 01:18

    List is a type of Iterable, but that doesn't mean that all Iterable objects are List objects. You can cast a List as an Iterable, but not the other way around.

    An apple is a type of fruit, but that doesn't mean that all fruits are apples. You can cast an apple as a fruit, but not the other way around.

提交回复
热议问题