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

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

I called a getElements method which returns Iterable.

I did this:

List elements = (List

        
10条回答
  •  -上瘾入骨i
    2021-02-20 01:15

    why not:

        Iterable i = ...; //is what you have
        List myList = new LinkedList();
        for (Element e:i) {
            myList.add(e);
        }
    

    ? needs no google lib.

提交回复
热议问题