问题创建一个双数组列表 [英] issue creating a double array list
问题描述
是否有任何理由休耕code将使编译错误?
Is there any reason the fallowing code would give A compile error ?
Import java.util.*;
public class Storageclass
// class used to store the Student data
{
// creates the private array list needed.
private ArrayList<String> nameList = new ArrayList<String>();
private ArrayList<double> GPAList = new ArrayList<double>();
private ArrayList<double> passedList = new ArrayList<double>();
}
这是由一个主文件中的类访问有更多的类通过它没有这个错误的一部分。当我运行这个两个双ArrayList的给我这个错误。
this is in a class access by a main file there is more in the class by it not part of this error. when I run this the two double arrayList give me this error.
Storageclass.java:8: error: unexpected type
private ArrayList<double> GPAList = new ArrayList<double>(1);
^
required: reference
found: double
我不知道为什么,或这是什么错误意味着任何帮助将是AP preciated。
I am not sure why or what that error means any help would be appreciated.
〜感谢您的帮助是一个令人尴尬的错误新手我做了,但希望全这可以帮助其他人。
~ Thanks for the help was a embarrassingly novice mistake I made, but hope full this can help some other person.
推荐答案
由于所有的泛型类型&LT; T&GT;
是的在运行时擦除以对象
每次到位类型的 T
还必须扩展对象。所以你不能设置 T
是原始类型如双击
,但你可以使用它的包装类双击
。试试这个方法:
Since all generic types <T>
are erased at runtime to Object
every type you put in place of T
must also extend Object. So you can't set T
to be primitive type like double
but you can use its wrapper class Double
. Try this way:
private List<Double> passedList = new ArrayList<Double>();
或因为java7目录略短版
or since Java7 little shorter version
private List<Double> passedList = new ArrayList<>();
此外,如果你尝试不用担心添加
的变量双击
键入这样的阵列,因为这将是 autoboxed 以双击
。
Also don't worry if you try to add
variable of double
type to such array since it will be autoboxed to Double
.
这篇关于问题创建一个双数组列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!