Eclipse 消息说 List cannot be resolved to a type

新手上路,请多包涵

我正在 eclipse 中尝试以下代码:

 public class A {
    List<Integer> intList = new ArrayList<Integer>();
}

但是它给我一个错误提示:List cannot be resolved to a type and ArrayList cannot be resolved to a type。

我需要添加一些库吗?我该怎么做?

原文由 Alan2 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 1.2k
2 个回答

您可以按 Shift + Ctrl + O 进行自动导入。

原文由 christian.vogel 发布,翻译遵循 CC BY-SA 3.0 许可协议

将以下内容放在源文件的顶部:

 import java.util.ArrayList;
import java.util.List;

这里 解释了包是什么以及 import 语句是如何工作的。

原文由 Taymon 发布,翻译遵循 CC BY-SA 3.0 许可协议

推荐问题