What is the use of constants for property keys?

Recently, I came across a lot of Java code that relies on “property files” for configuration. But instead of plain old string literals, the code uses constants (static final strings) to get property values.

I find this additional level of annoyance annoying because I need to search TWO strong> on EITHER . If I start with the property observed in the configuration file, I must first find the name of the property to find the Java constant, and then search again to find the references to the constant in the code. If I start in the code, I have to find the actual constant value before I can then determine the value of the property in the configuration file!

What is the point?

I understand the importance of using constants to refer to keys in a resource set, usually in support of i18n. I mean simple, non-user configuration values. The only reason is to simplify changing the property name later, but this advantage is much less than the annoyance of IMHO, especially considering the ease of global search and replacement.

+5
source share
5 answers

If you need to change the value without recompiling, you will inevitably need a redirect, but executing another one is pretty stupid, unless the key should be mentioned in more than one place (which is a possible sign of poor separation of problems).

, ( ) , , , , . () - - , .

, , KISS.

+6

, .

+11

( ) , . , :

  • , typos , String
  • "ID" , "ID" XML. , .
  • , IDE .

, , - .

+5

, , , , XML , , , , . , , .

, , , , ( ), , .

0

, "com.foo.bar.whatever", .

0

All Articles