I want to implement a method who decide from what java enum to get a specific value. For example:
public enum Credentials1 {
USERNAME("user"),
PASSWORD("pass");
}
public enum Credentials2 {
USERNAME("user"),
PASSWORD("pass");
}
and then, in another class I want a generic method to decide, based on another param, what enum should I use to get the correct user. Something like:
public String decide(here I should pass something?) {
switch (myParam) {
case "1":
return Credentials1.USERNAME;
case "2":
return Credentials2.USERNAME;
}
return "";
}
Can this be achievable, because I didn't succeed? And think that besides USERNAME and PASSWORD I will have a lot of constants in those enums.