Java Reference
In-Depth Information
Although this solves the puzzle, it is a very bad thing to do. It violates the advice of Puzzle 58 : If
two overloadings of the same method can be applied to some parameters, they should have
identical behavior. In this case, e.equals(e) and e.equals((Object)e) return different results.
The potential for confusion is obvious.
There is, however, a solution that doesn't violate this advice:
final class Enigma {
public Enigma() {
System.out.println(false);
System.exit(0);
}
}
Arguably, this solution violates the spirit of the puzzle: The println invocation that produces the
desired output appears in the Enigma constructor, not the main method . Still, it does solve the
puzzle, and you have to admit it's cute.
As for the lesson, see the previous eight puzzles and Puzzle 58 . If you do overload a method, make
sure that all overloadings behave identically.
< Day Day Up >
 
 
Search WWH ::




Custom Search