dimanche 21 janvier 2018

java function return more state types that Boolean

If I have just two states(true and false), my function can return boolean and based on its return value I can do some stuff.

boolean checkFoo(Object foo) {

 // .....
 return true/false;
}

and if I have four states:

I can use enum and use that return enum from function..

 public enum StateEnum { //... }

 StateEnum checkFoo(Object foo) {

 // .....
 return StateEnum.STATE1/StateEnum.STATE2/StateEnum.STATE3/StateEnum.STATE4;
}

but this enum just used for this function and has no other uses, is there any other clean way for this situation? something like returning string??

Aucun commentaire:

Enregistrer un commentaire