Reputation: 2031
From just an efficiency standpoint, in Java, are there any advantages to using static final variables if the strings will only be used once in the code?
Upvotes: 1
Views: 457
Reputation: 44970
Most likely no. The Java compiler interns the string constants during compilation so creating the constant manually is not a performance optimization. Moreover G1GC has string deduplication feature as per JEP 192: String Deduplication in G1.
The static final
field is usually created to improve the code readability, to give meaning to a specific string value and avoid commenting.
Upvotes: 3