不兼容的类型ListList和ArrayList的ArrayList [英] Incompatible types List of List and ArrayList of ArrayList

查看:172
本文介绍了不兼容的类型ListList和ArrayList的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< Integer>> 然后你就可以向它添加 LinkedList< Integer> 了。但是你不能为 ArrayList< ArrayList< Integer>> 执行此操作,因此后者不可能是 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>>.

这篇关于不兼容的类型ListList和ArrayList的ArrayList的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆