I am finding this question difficult to understand. I would have thought you are supposed to find two values that will cause the program to print, “Success.” Needless to say, that code can be relied on to crash with an exception.Istvan Kovacs wrote:. . .
Campbell Ritchie wrote:You have shown several examples of code which appear to fail
Campbell Ritchie wrote:how are you going to do that?
Campbell Ritchie wrote:And?
You have shown several examples of code which appear to fail. If the idea behind the puzzle is to get it to print, “success,” how are you going to do that?
Campbell Ritchie wrote:I can think of a few things where the usual == and != operators seem to be at odds with equals(), I am keeping quiet about them, too.
It would appear one of my examples where == and != operators seem to be at odds with equals() caused it to print, “Success.” What a surprise!
Campbell Ritchie wrote:I can think of a few things where the usual == and != operators seem to be at odds with equals(), I am keeping quiet about them, too.
It would appear one of my examples where == and != operators seem to be at odds with equals() caused it to print, “Success.” What a surprise!
Campbell Ritchie wrote:You can create a similar puzzle with NaNs, but all the Boolean tests would have to be reversed.
Campbell Ritchie wrote:Here is the simplest version of f() applied to your original code, along with actual type parameters given to the declaration of function:
It should be possible to apply a method reference in line 34 instead: Function::identity.
I just wanted to ask if your solution would still work if I added a check asserting that !Objects.equals(item1, function.apply(item1)) and the same for item2, but then Mike provided the exact solution I had in mind.
Hold that thought. Tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
|