Java JCreator List引用引用ArrayList不起作用?

时间:2015-11-23 08:49:57

标签: java arraylist

您好我一直在尝试使用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>();
    }

1 个答案:

答案 0 :(得分:1)

您只需导入ListArrayList

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