我正在尝试在Room中进行聚合课程。我有Owner和Pet两个类,我想将它们都放在聚合类-List中。 List类是仅用于分组对象Owner和Pet的默认类。 因此,在应用程序中,我希望有可能创建新的Owner和Pet,但是List仅用于处理这些类,而我不能做新的类。 我知道,这可能会造成混淆,但我真的不知道如何更好地解释它。
列表:
public class List {
private int id;
private ArrayList<Owner> owners;
private ArrayList<Pet> pets;
public List(int id, ArrayList<Owner> owners, ArrayList<Pet> pets) {
this.id = id;
this.owners = owners;
this.pets = pets;
}
所有者
@Entity(tableName = "owner_table")
public class Owner {
@PrimaryKey(autoGenerate = true)
private int ownerId;
private String firstName;
private String lastName;
public Owner(String firstName, String lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
宠物:
@Entity(tableName = "pet_table")
public class Pet {
@PrimaryKey(autoGenerate = true)
private int petId;
private String name;
private String birthday;
public Pet(String name, String birthday) {
this.name = name;
this.birthday = birthday;
}