java—如何用抽象类中的值保存对象?

zed5wv10  于 2021-07-09  发布在  Java
关注(0)|答案(0)|浏览(154)

我有课

@Data
public class ScreenshotInput extends InputModel implements Serializable {
  private static final long serialVersionUID = 1L;

  private final byte[] image;
  private final Timestamp timeCreated;

  public ScreenshotInput(byte[] image, String taskName, Timestamp timestamp) {
    super(taskName);
    this.image = image;
    this.timeCreated = timestamp;
  }
}

以及我的抽象inputmodel类:

@Data
public abstract class InputModel {
  private String taskName;
  private String userName;

  public InputModel(String taskName) {
    this.taskName = taskName;
    this.userName = Preferences.userRoot().get("username", "username");
  }
}

当我想保存创建的对象screenshotinput时,只有screenshotinput类中定义的值被保存到我的对象:image和timestamp。值taskname和username是可用的(例如,当我想在将对象保存到桩上之前打印它时),但它们不在桩上的对象中。默认情况下,如何将inputmodel中的变量写入对象?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题