【发布时间】:2011-03-02 17:34:35
【问题描述】:
可能的重复:
What does it mean to program to a interface?
Interface List - java
你好。我被要求在几个类中使用接口列表。我的老师说这是为了让将来更容易交换一个实现。我被要求尽可能用 List 替换 ArrayList,但我仍然不完全确定这意味着什么。我想我了解什么是界面,但不确定如何进行更改。
因此,例如,这是我应该使用 List 修改所有 ArrayList 位的类的第一部分。任何帮助表示赞赏
public class Simulator
{
// Constants representing configuration information for the simulation.
// The default width for the grid.
private static final int DEFAULT_WIDTH = 70;
// The default depth of the grid.
private static final int DEFAULT_DEPTH = 40;
// List of animals in the field.
private ArrayList<Animal> animals;
【问题讨论】:
-
为什么在第一次发帖几分钟后又发了两次同样的问题:stackoverflow.com/questions/5170893/interface-list-java !!!!!!
标签: java