1 package com.test; 2 3 import java.util.Comparator; 4 public class Order { 5 6 public static void main(String[] args) { 7 Comparator<Integer> naturalOrder = new Comparator<Integer>(){ 8 public int compare(Integer first, Integer second) 9 { 10 return first < second ? -1 :(first == second ? 0:1); 11 } 12 }; 13 14 /*This one is obviously broken - outputs 1 instead of 0 - Why?*/ 15 System.out.println(naturalOrder.compare(new Integer(42), new Integer(42))); 16 17 /*This one works but is still broken - outputs 0 as expected! - Why is this broken?*/ 18 System.out.println(naturalOrder.compare(42,42)); 19 } 20 } 21