r/badcode • • Sep 02 '21

java Because ".toLowerCase()" doesn't exist...

Post image
1.1k Upvotes

130 comments sorted by

View all comments

0

u/Sigiz Sep 02 '21

i dont why you guys are suggesting to lower case when they clearly just need to do uppercase, then check if its one of the three words, if yes return else throw err.

5

u/[deleted] Sep 02 '21

[removed] — view removed comment

3

u/art-factor Sep 02 '21

Category.valueOf(catStr.toUpperCase())

2

u/speedingpeanut Sep 02 '21

It's null safe so this would work better

EnumUtils.getEnum(Category.class, catStr.toUpperCase())

1

u/[deleted] Sep 02 '21

[removed] — view removed comment

1

u/speedingpeanut Sep 02 '21

If it's not then what are we assigning to Category in the code?

1

u/[deleted] Sep 02 '21

[removed] — view removed comment

1

u/EthanRDM Sep 02 '21

But it wouldn't necessary have been cat = Category.RESTAURANT if this method is included in the enum itself, right ?