This is an update to the subsection “Testing Object Equivalence” in the “Operators” chapter of On Java 8. This will appear in the book in its next update. The relational operators == and != work with all objects, but their results can be confusing:// operators/Equivalence.java public class Equivalence { static void show(String desc, Integer n1, Integer n2) { System.out.println(desc ":"); System.out.printf( "%d==%d %b %b%n", n1, n2, n1 == n2, n1.
Published on February 03, 2021 16:00