我想防止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)