不兼容的类型 List of List 和 ArrayList of ArrayList [英] Incompatible types List of List and ArrayList of ArrayList
本文介绍了不兼容的类型 List of List 和 ArrayList of ArrayList的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下行给了我错误:
Incompatible Types.
List<List<Integer>> output = new ArrayList<ArrayList<Integer>>();
是什么原因?
编辑
我知道如果我将第二个 ArrayList 更改为 List,它不会给我错误.我想知道错误的原因.谢谢
I understand if I change my second ArrayList to List, it does not give me error. I want to know the reason of error though. Thanks
推荐答案
如果你有一个 List
那么你就可以添加一个 >
LinkedList<;Integer>
到它.但是你不能对 ArrayList
这样做,所以后者不可能是 List
的类型>.>
If you had a List<List<Integer>>
then you'd be able to add a LinkedList<Integer>
to it. But you can't do this for an ArrayList<ArrayList<Integer>>
, so the latter can't possibly be a type of List<List<Integer>>
.
这篇关于不兼容的类型 List of List 和 ArrayList of ArrayList的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文