java创建唯一的增量id并将其添加到集合中
问题是,我需要为每个新客户创建新的增量ID,并将其添加到集合中,我正在尝试使用while循环,但它似乎不正确
public class Bank {
private String name;
private Set<Customer> customers = new HashSet<Customer>();
private Set<AbstractAccount> accounts = new HashSet<AbstractAccount>();
private Integer lastCustomerId = 0;
private Integer lastAccountId = 0;
public Integer addCustomer(String firstName, String lastName) {
// generate id from lastCustomerId and increment it
// add to Set
return lastCustomerId++;
}
public Integer addAccount(Integer ownerId, AccountType type) {
// add to Set
}
}
# 1 楼答案
我不确定这是不是你想要的