I have got a method which searches for User in my db etc. and when user cannot be found, then null is returned
I am quite sure that there is better way to handle this problem and avoid null-pointers. I have heard about Optional class in Guava or Java8.
But I am still not sure if it is good to "wrap" my User class into Optional, because when user is found I will also have to return Optional and then get the user from returned instance. It will cause a little boilerplate code
what do you think about that?
Aucun commentaire:
Enregistrer un commentaire