Is making an empty string constant worth it?

前端 未结 18 807
無奈伤痛
無奈伤痛 2021-01-01 10:11

I have a co-worker that swears by

//in a singleton \"Constants\" class
public static final String EMPTY_STRING = \"\";

in a constants class

18条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-01 10:42

    Why on earth would you want a global variable in Java? James Gosling really tried to get rid of them; don't bring them back, please.

    Either

    0 == possiblyEmptyString.length()
    

    or

    possiblyEmptyString.isEmpty() // Java 6 only
    

    are just as clear.

提交回复
热议问题