The purpose of using a constants pool for immutable constants

Posted by patstuart on Programmers See other posts from Programmers or by patstuart
Published on 2014-05-30T19:09:23Z Indexed on 2014/05/31 3:51 UTC
Read the original article Hit count: 546

Filed under:
|
|

Originally posted at stackoverflow.com/q/23961260


I come across the following code with a lot of frequency:

if (myArray.length == Constants.ZERO_INT) 

or

if (myString != null && !myString.equals(Constants.EMPTY_STRING)) 

Neither of these makes much sense to me. Isn't the point of having a constant pool for ease of code appearance and to allow for modularity? In both of the above cases, it just looks like needless noise that accomplishes neither objective.

My question: what is the purpose of using a constants pool for variables like this which will never change? Or is this just cargo cult programming? If so, then why does it seem to be prevalent in the industry? (I've noticed it with at least two different employers I've worked with).

© Programmers or respective owner

Related posts about java

Related posts about coding-style