Al Hobbs wrote:. . . The stream I want to use is in a while loop. . .
That isn't clear from your posted code, but it doesn't strike me as correct to use a mixture of Stream and loops.
the scope of maxHand is only in one loop, so I initialized it and declared in final when it was being made.
(I just added final int.) It seems to have gotten rid of the problem.
Is that an appropriate solution?
Thanks for your replies!
Marking a variable
final is usually a good solution, so keep the
final modifier, but I think there is a better way to do things. If
getHandStrength() returns an
int, I suggest you use a different method from map. Try
this, which returns a different kind of Stream, which has a method to calculate the maximum if present. You may end up writing something like
orElse(0) in case nobody is playing at all.
The result from
getHandStrength() is not reassigned in the Stream, so that won't be the problem.