Reputation: 846
Suppose there is some bean named employee:
and has many fields like first name, last name, emp no, age , addr, designation etc.
Is there a way by which I can test if none of the fields have been set?.
I mean, I get a reference through which I can get all values one by one and check if all are empty/null. but is there a better way to find if none of the fields have been set in the bean
Upvotes: 0
Views: 205
Reputation: 48287
Yes, you can do it exactly like you are thinking...
there is no Out of the Box method for that, but you can
create a method that return a boolean
and this represent the state of the Bean you want to check...
public boolean isProperlyInitialized(){
boolean condition1 = age!=0;
boolean condition2 = ...;
return condition1 && condition2 &&....;
}
and implemented in the code
Bean b = new Bean();
if(b.isProperlyInitialized){
//Do something cool
}
Upvotes: 2