问题创建一个双数组列表 [英] issue creating a double array list

查看:118
本文介绍了问题创建一个双数组列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有任何理由,休眠代码会给出编译错误?

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>();
}

这是一个主文件的类访问在类中有更多它不是这个错误的一部分。当我运行这两个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

我是不知道为什么或什么错误意味着任何帮助将不胜感激。

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.

推荐答案

由于所有通用类型< T> =http://docs.oracle.com/javase/tutorial/java/generics/erasure.html =noreferrer>擦除在运行时到对象每个类型你放在 T 也必须扩展Object。因此,您不能将 T 设置为原始类型,如 double ,但可以使用其包装类。尝试这样:

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<>();

如果您尝试添加变量 double 类型到这样的数组,因为它将是 autoboxed Double

Also don't worry if you try to add variable of double type to such array since it will be autoboxed to Double.

这篇关于问题创建一个双数组列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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