gpt4 book ai didi

java - 一个 ArrayList 添加 2 个不同的选项

转载 作者:行者123 更新时间:2023-12-02 11:45:45 25 4
gpt4 key购买 nike

我的问题是我必须使用一个 Arraylist 并添加两个选项

1.任务(内容、开始时间、开始结束、难度)

contents- String
startTime,startEnd- Localtime
difficulty- boolean easy/difficult
  • 发生的事情(内容、开始时间、开始结束、重要、训练)
  • contents- String
    startTime,startEnd- Localtime
    important- boolean Yes/No
    training- boolean Yes/No

    是否可以将两个不同的选项合并到一个数组列表中?

    最佳答案

    通用属性接口(interface)

    public interface MyI {

    public String getContens();

    public LocalTime getStartTime();

    public LocalTime getStartEnd();

    }

    然后为独特实例的覆盖范围创建模型:

    public class Task implements MyI {

    private String contens;

    private LocalTime startTime;

    private LocalTime startEnd;

    private boolean difficulty;

    public boolean isDifficulty() {
    return difficulty;
    }

    public void setDifficulty(boolean difficulty) {
    this.difficulty = difficulty;
    }

    public void setContens(String contens) {
    this.contens = contens;
    }

    public void setStartTime(LocalTime startTime) {
    this.startTime = startTime;
    }

    public void setStartEnd(LocalTime startEnd) {
    this.startEnd = startEnd;
    }

    @Override
    public String getContens() {
    return this.contens;
    }

    @Override
    public LocalTime getStartTime() {
    return this.startTime;
    }

    @Override
    public LocalTime getStartEnd() {
    return this.startEnd;
    }

    }

    public class Happening implements MyI {

    private String contens;

    private LocalTime startTime;

    private LocalTime startEnd;

    private boolean important;

    private boolean training;

    public boolean isImportant() {
    return important;
    }

    public void setImportant(boolean important) {
    this.important = important;
    }

    public boolean isTraining() {
    return training;
    }

    public void setTraining(boolean training) {
    this.training = training;
    }

    public void setContens(String contens) {
    this.contens = contens;
    }

    public void setStartTime(LocalTime startTime) {
    this.startTime = startTime;
    }

    public void setStartEnd(LocalTime startEnd) {
    this.startEnd = startEnd;
    }

    @Override
    public String getContens() {
    return this.contens;
    }

    @Override
    public LocalTime getStartTime() {
    return this.startTime;
    }

    @Override
    public LocalTime getStartEnd() {
    return this.startEnd;
    }

    }

    现在您可以使用界面创建一个列表来保存两种类型的模型:

    List<MyI> myList = new ArrayList<MyI>();

    关于java - 一个 ArrayList 添加 2 个不同的选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48214504/

    25 4 0