您好我一直在尝试使用List引用来使用以下代码引用ArrayList:
import java.util.List;
public class Purse
{
private List<String> purseList;
public static final String EMPTY_STRING = "";
// constructs an ArrayList of Strings
public Purse()
{
purseList = new ArrayList<String>();
}
这让我回到了错误
"Purse.java:14: error: cannot find symbol
purseList = new ArrayList<String>();
^
symbol: class ArrayList
location: class Purse
1 error"
但是当我使用这组代码时没有问题,我该怎么做才能使用List而不是ArrayList
import java.util.ArrayList;
public class Purse
{
private ArrayList<String> purseList;
public static final String EMPTY_STRING = "";
// constructs an ArrayList of Strings
public Purse()
{
purseList = new ArrayList<String>();
}
答案 0 :(得分:1)
您只需导入List
和ArrayList
!
import java.util.ArrayList;
import java.util.List;
public class Purse
{
private List<String> purseList;
public static final String EMPTY_STRING = "";
// constructs an ArrayList of Strings
public Purse()
{
purseList = new ArrayList<String>();
}
}