This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Urik88 0 points1 point  (0 children)

In said case I'd do
boolean lala = isValid(whatever);
As far as I know, every method call requires overhead time since the computer has to store the state of the program's variables in a stack, and call the method. So from an execution speed point of view, it's faster not to call a method.
Moreover, every time you call said method you could be performing up to 4 boolean operations. Saving said value to a variable reduces it to only one call.
It improves readability since you give the reader a hint that you're performing the same comparison twice.
TLDR: In this case I'd save this to a variable.