I have a method that inserts a list of objects in the database:
public void insert(List<Object> objects){
}
Now, I need to insert a single object. I do not want to create a new method that does the insertion of a single object because it would duplicate a lot of code, so I do the following:
public void insert(Object object){
List<Object> objects = new ArrayList<>();
objects.add(object);
insert(objects);
}
I do not know if the above is correct, my knowledge of java is high level so I do not know how expensive it is for the system to convert the object to the arrangement and if this is a good development technique. Or if by some pattern or convention I must create a method to insert a single object.
Aucun commentaire:
Enregistrer un commentaire