The first way is simpler and significantly more performant and memory efficient. I’d change to an enum which is more type safe (takes up 24 bytes + 24 for each entry in Java but in a proper language would typically be 4 bytes in its entirety) and an exhaustive switch.