I have come across two ways to return a position in an arrangement, in an autoincremental function and I wanted to know which one would be considered better and why
1.-
public Object returnObject()
{
objectIndex++;
return objeto[objectIndex-1];
}
2 .-
public Object returnObject()
{
Object objetoNuevo = objeto[objectIndex]
objectIndex++;
return objetoNuevo ;
}
The first option I like because it does not create a new instance of the object, it uses less lines, but it has a strange way of handling the index,
The second option seems simpler, although it uses a more code line and generates a new instance of the object, which does not seem to me at all a good practice either.
in cases like this one should resort to the efficiency of the code or the simplicity of it?