Here is my problem, I have 2 classes in this example (but almost 10 IRL) auto generated from an xsd
public Toto {
public Toto(String date, String valueFromToto) {
this.date = date;
this.valueFromToto = valueFromToto;
}
public String getDate() {
return this.date;
}
public String getValueFromToto() {
return this.valueFromToto;
}
}
public Titi {
public Titi(String date, String valueFromTiti) {
this.date = date;
this.valueFromTiti = valueFromTiti;
}
public String getDate() {
return this.date;
}
public String getValueFromTiti() {
return this.valueFromTiti ;
}
}
And I'd like to have the same process for each classes But I don't know the best way to do this. I was looking about "reflection" but that seams to be a bad solution. How about functionnal interface ?
public String test(List<Toto or Titi> liste, LocalDate date) {
for (Toto or Titi o : liste) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("ddMMyyyy");
LocalDate localDateToTest = LocalDate.parse(o.getDate(), formatter);
if (date.isAfter(localDateToTest))
return o.getValueFromToto() or o.getValueFromTiti();
}
return "";
}
If someone can point me in the right direction Thanks in advance