我确实对将 null 添加到我将使用的示例中的列表有疑问Collections.singletonList(value)
所以可以说我确实有这样的东西:
String value = null;
List<String> test = Collections.singletonList(value);
在这种情况下,我将得到包含 null 的单例列表。所以我们确实有包装单个空值的 List 对象。
所以我的问题是关于添加value变量检查。
String value = null;
List<String> test;
if(value == null){
test = null;
}
else{
test = Collections.singletonList(value);
}
值得这样做吗?
手掌心
茅侃侃
相关分类