I made this method:
public void update(){
for(GameObject object : objects)
object.update();
}
And then my IDE I could use for each instead any, that I what thought I did, any I let it replace it. This it what it gave me:
public void update(){
objects.forEach(GameObject::update);
}
At first glance, this seems to better, and then my IDE was saying you can convert this to lambda expressions which would be:
public void update(IUpdater updater){
objects.forEach((object) -> object.update());
}
Which gave the impression that GameObject:: update
is some time of lambda expressions, bare in mind the only new stuff to java 8 that I know of (object) -> object.update()
replaces anonymous class guess it still under the hood somewhere.
Does this essence 'objects.forEach(GameObject::update)' means:
public void update(){
objects.forEach(new Consumer<GameObject>() {
@Override
public void accept(GameObject object) {
object.update();
}
});
}
And if that is the case then would my original method be more efficient that GameObject::update
. Have left it the method as GameObject::update
but will change it back if find original method be more efficient.
I am asking the question on a purely on the basis of performance.