我尝试在我的扩展类中创建一个构造函数,以便在我的主类中创建对象。当我生成默认的 eclipse 构造函数时,它会显示超类的所有字段,当我尝试在主数据库中创建对象时,我需要放置所有字段。
这是我的Person类:
public class Person {
private String id;
private String name;
private String gender;
private String country;
private String cities;
private String birthDate;
private String deathDate;
private List<String> aliases = new ArrayList<String>();
private List<String> tags = new ArrayList<String>();
public Person(String id, String name, String gender, String country, String cities, String birthDate,
String deathDate, List<String> aliases, List<String> tags) {
this.id = id;
this.name = name;
this.gender = gender;
this.country = country;
this.cities = cities;
this.birthDate = birthDate;
this.deathDate = deathDate;
this.aliases = aliases;
this.tags = tags;
}
这是我的扩展,组类:
public class Group extends Person{
private String name;
private String country;
private String cities;
private String beginDate;
private String endDate;
private List<String> aliases = new ArrayList<String>();
private List<String> tags = new ArrayList<String>();
private List<Person> members = new ArrayList<Person>();
public Group(String id, String name, String gender, String country, String cities, String birthDate,
String deathDate, List<String> aliases, List<String> tags, String name2, String country2, String cities2,
String beginDate, String endDate, List<String> aliases2, List<String> tags2, List<Person> members) {
super(id, name, gender, country, cities, birthDate, deathDate, aliases, tags);
name = name2;
country = country2;
cities = cities2;
this.beginDate = beginDate;
this.endDate = endDate;
aliases = aliases2;
tags = tags2;
this.members = members;
}
这是生成的构造函数(巨大的构造函数)当我尝试在我的主上创建对象时,它需要所有字段(甚至是Person的类字段),那么有没有办法通过仅填充Group类的字段来创建Group对象?提前致谢。
弑天下
慕丝7291255
相关分类