3 ms·
I wanted ease of use and comfort methods when using Java’s legacy Enum. Like resolving a value by its case-insensitive name or ordinal. Or easily, flexibly, and
by jimofl 10mo ago
I wanted ease of use and comfort methods when using Java’s legacy Enum. Like resolving a value by its case-insensitive name or ordinal. Or easily, flexibly, and quickly, pretty-printing (a subset of) the Enum’s values, again by name and/or ordinal.
As old as Java’s Enum is, I think it’s absolutely fantastic. I just wanted to increase its fantastic-ness!
- layer8 10mo agoYou can use java.lang.ClassValue to store per-(enum-)class state generically. Meaning, instead of having to instrument each enum class, you could have MyEnumHelper.of(AnyEnum.class) .whateverFunctionalityYouWant() where the of() implementation uses ClassValue to store the cached data.
- jimofl 10mo agoThis is a fantastic response! Tysvm for posting, and in detail.
- jimofl 10mo agoBTW, the solution I provided in my library already does exactly what you are describing in terms of not needing to instrument each enum class. The high value of your response, to me, is discovering I can replace my custom "Memoizer" mechanism with a platform-provided (and therefore superior to my custom code) solution with java.lang.ClassValue.
- deleted 9mo ago[deleted]