mardi 28 août 2018

Java: Finding out if all numeric fields of an object are 0

I have a java-8 class:

  class MyClass{
    double field1;
    double field2;
    int field3;
    ...
    float fieldN;

    boolean isEmpty() {
        // I want to implement this such that if all my numeric fields are 0's then return true else false
    }

}

What would be the most elegant way of implementing isEmpty() instead of adding many different if(fieldX == 0 ) conditions in there ?

Aucun commentaire:

Enregistrer un commentaire