If I use the construction method of Constants, the key in the fieldcache attribute is the attribute name and is not capitalized, but when I use the asxxxx method, the parameter code will be capitalized, resulting in no corresponding value
Why not capitalize when put?
Although the Java specification constants should be all capitalized, this is not mandatory. It is better if they are also capitalized when put!
Comment From: jhoeller
Capitalizing on put could have side effects when the same constant is declared with different casing (since fields are case-sensitive). Instead, we could leniently find fields with the provided casing in asObject
, but even that would create an inconsistency with getNames
and related methods.
Since Constants
is not considered a general utility but rather a Spring-style adapter for classic Java constants used in several framework classes, we'll rather leave it as-is. For custom purposes, it is straightforward enough to create a similar adapter of your own, inspired by Spring's Constants
class.