lundi 6 décembre 2021

Substitutions in variable name in java

Not sure if this is possible in JAVA, and also don't know what it's called so I'm not sure what to look for, but if it is possible I really wanted to implement the same in my logic. I know we can substitute value but how to substitute variable that I am not sure.

public interface Constants {
 GENDER_${MALE} = "where Gender = 'MALE' ";
 GENDER_${FEMALE} = "where Gender = 'FEMALE' ";
}

public class Impl {
  System.out.println(Constants.GENDER_MALE);
}

Expected O/P : where Gender = 'MALE';

I just don't want to use if else condition, if Male then return male specific where clause else female.. because in actual code there are almost 30-35 if else conditions, just want to reduce that, if possible.

Aucun commentaire:

Enregistrer un commentaire