I have a pojo class
class Foo{
String a
String b
.
.
// nearly 250 data members
// all have getters and setter
}
Now when i create object of class
how can i check that any data member in object is blank
i am using following approach
public boolean clearBlank()
{
if(StringUtils.isBlank(this.getA()))
return true;
if(StringUtils.isBlank(this.getB()))
return true;
if(StringUtils.isBlank(this.getC()))
return true;
.
.
.
// similarly for all 250 data member
return false;
}
IS there any better approach intead of checking by calling all 250 getters of object?
Yes, you can use Java Reflection to go through all of the fields of the object and get their values to do the comparison.
Like this: