vendredi 30 octobre 2020

If condition then put value many times in java

I have two objects with many parameters. I need to compare it by each field and put information about what field is different

How to do it clean?

I'm not happy with something like that

if(<condition>) {
    list.add(object.getParam());
}
if(<condition>) {
    list.add(object.getParam());
}
if(<condition>) {
    list.add(object.getParam());
}
if(<condition>) {
    list.add(object.getParam());
}
(...)
   

Maybe there is cleaner way to do it by stream for example?

Aucun commentaire:

Enregistrer un commentaire