Today my college presented to me an argument about not use some primitives that I never heard before. I would like to see what you guys think about it.
We have a class in our project like:
class Order {
private long id;
private String name;
// more fields
}
We have a builder for this class for all the fields.
I always try to use primitive¹ instead of objects to store values, only to evict the possibility of null pointers in the middle of my code, specially as parameters on my methods. You can notice the long
primitive in this class too.
But my college said to me that he prefers to use, in this case, the object Long
.
His argument: there is a risk to forgot to set the Long value and the default will be 0 (zero), what could bring some problems.
I made the change and not discussed with him about it, because our id
s never start with zero, already preventing some mistake about get the wrong Order with zero
id.
But I was thinking if there are some another problem that could be prevented not using the primitive in the same line of his logic.
1. I'm aware about the Primitive Obssession. But I don't think that is related of this subject