vendredi 5 août 2016

Is it a bad practice to check null before returning from a getter?

I wanna prevent getters from returning null values, like the examples bellow. Is this a bad practice?

Example 1

public Integer getMinutes() {
   if (minutes == null)
       minutes = 0;
   return minutes;
}

Example 2

public List getTasks() {
   if (tasks == null)
       tasks = new ArrayList();
   return tasks;
}

Aucun commentaire:

Enregistrer un commentaire