Fred Masen wrote:
This part of the code imply it return true.
else will return false.
Do you mean an explicit empty return; statement?Junilu Lacar wrote:. . . . The only time you can have an implied return is if a method is declared as void.
Campbell Ritchie wrote:
Do you mean an explicit empty return; statement?Junilu Lacar wrote:. . . . The only time you can have an implied return is if a method is declared as void.
Fred Masen wrote:I agree about the language specifications your described. But in the example proposed and the changes I made " It implies" true or return false. The program works properly , if you change the Howdy it will return the appropriate answer and it is working fine. The program knows that it is true at the starts and else false. The reason I am saying that is that the code I changed does not have a "TRUE s" statement so it it indirectly "implies" true at the beginning.
Is there such a thing? Yes, I think there probably is; I shall let you go through some bytecode, but I think a return is added to the bytecode as the last line of a void method.Junilu Lacar wrote:. . . an implicit/implied return when you just fall out of a method at the end.
Which shows you were right.Junilu Lacar wrote:. . . The bytecode is exactly the same . . .
Campbell Ritchie wrote:Which shows you were right.
I think a return is added to the bytecode as the last line of a void method
Frank Masen wrote:one thing I do the mos nowt is trying the code the most I can using my Eclipse IDE before posting the program. Try yourself and you will see it works fine now
Fred Masen wrote:Well try to change howdy howdy to : how howdy and it returns "equal not". Basically this very very very simple program does what it is supposed to do it, comparing 2 Strings and telling you if they are the same or not.
Fred Masen wrote:Well try to change howdy howdy to : how howdy and it returns "equal not".
Ricky Bee wrote:
3 - Same result of 2, but in a simplified way:
You wrote:No in my example the (return true is removed) only the return false remains. And you can change the Strings and it will work properly and give you each time the correct answer
Junilu Lacar wrote:
Ricky Bee wrote:
3 - Same result of 2, but in a simplified way:
Make sure you understand the difference between using == instead of equals() here -- code like this should immediately raise a red flag as it is likely to be a bug.
Assuming appropriate checks to guard against NullPointerException had already been made, this would be more correct:
Ricky Bee wrote:
In some situations, something like that it can return FALSE even if the value of those Strings looks the same. That's the case you are showing here:
Fred Masen wrote:Remove the return true statement and you got a poorly designed working program
Hahahahahahahahahahaha!Junilu Lacar wrote:. . . This is what I see your "fixed working program" as: https://imgflip.com/i/2gjqa5
Campbell Ritchie wrote:Is that the Boyarsky and Selikoff book? Have you looked here whether that has been reported before?
Technically the exam says to assume code snippets have surrounding code that is ok. So while this wasn’t intentional, you can assume the closing }
“Be very careful on the code examples. Check for syntax errors first: count curly braces, semicolons, and parentheses, and then make sure there are as many left ones as right ones. Look for capitalization errors and other such syntax problems before trying to figure out what the code does.”
On the real exam, when a code listing starts with line 1, it means that you’re looking at an entire source file.
Everyone is a villain in someone else's story. Especially this devious tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
|