gpt4 book ai didi

java - 接口(interface)列表 - java

转载 作者:行者123 更新时间:2023-11-29 10:06:55 25 4
gpt4 key购买 nike

<分区>

Possible Duplicates:
What does it mean to program to a interface?
Interface List - java

你好。我被要求在几个类中使用接口(interface)列表。我的老师说,这是为了将来更容易交换实现。我被要求尽可能用 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;

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com