且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

我应该将初始 java 字符串值从 null 设置为“"吗?

更新时间:2023-11-29 09:24:52

我不同意其他海报.使用空字符串是可以接受的.我更喜欢尽可能使用它.

I disagree with the other posters. Using the empty string is acceptable. I prefer to use it whenever possible.

在大多数情况下,空字符串和空字符串表示完全相同的东西——未知数据.是否用 null 或空 String 表示它是一个选择问题.

In the great majority of cases, a null String and an empty String represent the exact same thing - unknown data. Whether you represent that with a null or an empty String is a matter of choice.