小编Lui*_*ino的帖子

从getter返回之前检查null是否是不好的做法?

我想防止getter返回null值,例如下面的示例。这是不好的做法吗?

例子1

public Integer getMinutes() {
   if (minutes == null)
       minutes = 0;
   return minutes;
}
Run Code Online (Sandbox Code Playgroud)

例子2

public List getTasks() {
   if (tasks == null)
       tasks = new ArrayList();
   return tasks;
}
Run Code Online (Sandbox Code Playgroud)

java oop null

5
推荐指数
1
解决办法
1313
查看次数

标签 统计

java ×1

null ×1

oop ×1