althaf
08/13/2021, 1:17 PMenum class Role(val letter: Char) {
APPROVER('U'),
ADMIN('D'),
INQUIRER('R'),
OPERATOR('O');
}
we have create this enum for code readability and we don't have direct control over how server is returning constants for the user roles, so they have done it this way 'U' , R etc
apiRespose.role = "U"
Role.valueOf(apiResponse.role) will not work ,as it is expecting 'APPROVER' as input . How can i achieve same benefit of Role.valueOf( ) wrt ot the 'letter' attribute in the enumChris
08/13/2021, 1:26 PMenum class Role(val letter: Char) {
APPROVER('U'),
ADMIN('D'),
INQUIRER('R'),
OPERATOR('O');
companion object {
fun from(letter: Char) = values().find { it.letter == letter }
}
}
and use it like
Role.from(letter)
Is this what you’re after?hho
08/13/2021, 1:32 PMChris
08/13/2021, 1:36 PMalthaf
08/13/2021, 1:38 PMalthaf
08/13/2021, 1:41 PM