关于 ArrayList<Integer>[] x 的 Java 问题 [英] Java question about ArrayList&lt;Integer&gt;[] x

查看:30
本文介绍了关于 ArrayList<Integer>[] x 的 Java 问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于 ArrayList 数组,我一直有这个问题.也许你能帮上忙.

I have always had this one issue with arrays of ArrayLists. Maybe you can help.

//declare in class
private ArrayList<Integer>[] x;

//in constructor
x=new ArrayList[n];

这会生成有关未经检查的转换的警告.

This generates a warning about unchecked conversion.

但是

x=new ArrayList<Integer>[n];

是编译器错误.

有什么想法吗?

谢谢!

推荐答案

您不能制作泛型列表的数组.幸运的是,有解决方法.更幸运的是,有一个关于 泛型 的不错的网站,提供更多信息比您想知道的信息.该链接直接指向 Java 泛型中的数组部分.

You can't make a array of generics lists. Fortunately, there are workarounds. And even more fortunately, there is a nice site about Generics with more information than you'd ever want to know. The link goes straight to the Arrays in Java Generics part.

这篇关于关于 ArrayList<Integer>[] x 的 Java 问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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