Is StringUtils.EMPTY recommended? Is StringUtils.EMPTY recommended? java java

Is StringUtils.EMPTY recommended?


Of course not.Do you really think "" is not clear enough ?

Constants have essentially 3 use cases:

  1. Document the meaning of a value (with constant name + javadoc)
  2. Synchronize clients on a common value.
  3. Provide a shortcut to a special value to avoid some init costs

None apply here.


I use StringUtils.EMPTY, for hiding the literal and also to express that return StringUtils.EMPTY was fully expected and there should return an empty string, "" can lead to the assumption that "" can be easily changed into something else and that this was maybe only a mistake. I think the EMPTY is more expressive.


No, just use "".

The literal "" is clear as crystal. There is no misunderstanding as to what was meant. I wouldn't know why you would need a class constant for that. I can only assume that this constant is used throughout the package containing StringUtils instead of "". That doesn't mean you should use it, though.

If there's a rock on the sidewalk, you don't have to throw it.