This week's book giveaway is in the OCAJP forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide 1Z0-808 and have Jeanne Boyarsky & Scott Selikoff on-line! See this thread for details.
On the last section of the style guide there is an example of a method called isLeapYear. It returns a boolean value. Instead of returning a variable with a boolean value, one can insert an expression that evaluates to a boolean value?
I'm not sure what you mean by your question, could you write up (using the example) what you're thinking of?
As a side note, I tend to think of complex boolean operations in smaller pieces such as "is the value within limits" = (x < 100 && x > 0), "is the value a multiple of 3" = ((x % 3) == 0), etc.
So I would write plain statements like: boolean isXWithinBoundary = x < 100 && x > 0; boolean isXAMultipleOf3 = (x % 3) == 0;
The point of the example is that often times in code you have to debug why something returned true/false when you expected it to return the opposite. Its much easier from a debugging perspective if you have each "rule" listed as a separate boolean so you know which rule failed.
Originally posted by Chuck Holowecky: Instead of returning a variable with a boolean value, one can insert an expression that evaluates to a boolean value?
I'm not really clear on the question, but I think you are asking if you can assign the result to a variable rather than returning the result. The answer to that is "yes".
JavaBeginnersFaq "Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Joined: Feb 09, 2006
This is the section of code that I'm refering to. It seems odd to me to pass a return value that is an expression, instead of a single value or variable. I'm assume that the expression is evaluated and then the results (true/false) are passed back to whoever call the method.