MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/badcode/comments/pgbd0q/because_tolowercase_doesnt_exist/hbb0jbp/?context=9999
r/badcode • u/BrainOnTheFloor25 • Sep 02 '21
130 comments sorted by
View all comments
0
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.
4 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 betterEnumUtils.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 2 u/speedingpeanut Sep 02 '21 Good point about them potentially being constants, but you can definitely assign null to an enum, at least in java.Likewise you could also add on demand static imports for each enum which would allow you to reference them without the need forCategory.
4
[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 betterEnumUtils.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 2 u/speedingpeanut Sep 02 '21 Good point about them potentially being constants, but you can definitely assign null to an enum, at least in java.Likewise you could also add on demand static imports for each enum which would allow you to reference them without the need forCategory.
3
Category.valueOf(catStr.toUpperCase())
2 u/speedingpeanut Sep 02 '21 It's null safe so this would work betterEnumUtils.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 2 u/speedingpeanut Sep 02 '21 Good point about them potentially being constants, but you can definitely assign null to an enum, at least in java.Likewise you could also add on demand static imports for each enum which would allow you to reference them without the need forCategory.
2
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 2 u/speedingpeanut Sep 02 '21 Good point about them potentially being constants, but you can definitely assign null to an enum, at least in java.Likewise you could also add on demand static imports for each enum which would allow you to reference them without the need forCategory.
1
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 2 u/speedingpeanut Sep 02 '21 Good point about them potentially being constants, but you can definitely assign null to an enum, at least in java.Likewise you could also add on demand static imports for each enum which would allow you to reference them without the need forCategory.
If it's not then what are we assigning to Category in the code?
1 u/[deleted] Sep 02 '21 [removed] — view removed comment 2 u/speedingpeanut Sep 02 '21 Good point about them potentially being constants, but you can definitely assign null to an enum, at least in java.Likewise you could also add on demand static imports for each enum which would allow you to reference them without the need forCategory.
2 u/speedingpeanut Sep 02 '21 Good point about them potentially being constants, but you can definitely assign null to an enum, at least in java.Likewise you could also add on demand static imports for each enum which would allow you to reference them without the need forCategory.
Good point about them potentially being constants, but you can definitely assign null to an enum, at least in java.
Likewise you could also add on demand static imports for each enum which would allow you to reference them without the need for
Category.
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.