I have a problem. I dont know how to store current LocalDate
in my program.
I have 2 classes:
public class Footballer extends Person {
private int age;
private List<Team> teams = new ArrayList<>();
public Footballer(int age) {
this.age = age;
}
public void addTeam (Team team1) throws IOException {
teams.add(team1);
team1.addFootballer(this);
}
}
And similar class Team
. I want to store LocalDate
when method addTeam
was called. How to do this?
Since this is a property of Footballer, you can add a LocalDate property to the class, then set it when the addTeam is invoked, and finally add a getter for that field. Eg
public class Footballer extends Person {
private int age;
private List<Team> teams = new ArrayList<>();
private LocalDate dateWhenPlayerAdd = null;
public Footballer(int age) {
this.age = age;
}
public void addTeam (Team team1) throws IOException {
teams.add(team1);
this.dateWhenPlayerAdd=LocalDate.now();
team1.addFootballer(this);
}
public LocalDate getDateWhenPlayerAdd() {
return this.dateWhenPlayerAdd;
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.