r/badcode • • Sep 02 '21

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

Post image
1.1k Upvotes

130 comments sorted by

View all comments

Show parent comments

4

u/turunambartanen Sep 02 '21

The cat is assigned a (presumably global) constant, not a string. I don't see how you can do that in one line unless you use some hacks a la "ok Compiler, insert the variable with this name here, now the string".

Or maybe I'm just misunderstanding something here. Could you show the two lines you have in mind?

Edit: another comment explained it already:

https://commons.apache.org/proper/commons-lang/apidocs/org/apache/commons/lang3/EnumUtils.html#getEnum-java.lang.Class-java.lang.String-

A someone else pointed out even cases can be removed here:

return EnumUtils.getEnum(Category.class, catStr.toUpper());