I have an Item[] items that contains some basic statistics about myself.
public float getAttackDamage() { float bonus = 0; for(int i = 0 ; i < items.length; i++){ if(items[i] != null){ bonus += items[i].getAttackDamage(); } } return baseAttackDamage + attackDamageScaling * level + bonus; }
The above code is how I currently getAttackDamage() over the elements of my characters and apply their getAttackDamage() to the return result.
Is there a way to rewrite this instead of using lambda expressions? I tried the following:
public float getAttackDamage() { float bonus = 0; Arrays.stream(items).forEach(i -> bonus += i.getAttackDamage()); return baseAttackDamage + attackDamageScaling * level + bonus; }
But this did not work (compiler error). Is it possible?
source share