Brainteaser: Broken Comparator

Question: The following program returns result “1″, which indicates that first Integer value is greater than the second, why?

import java.util.*;

public class Example  {

   public static void main(String[] args)  {
      System.out.println("Result: " +
	   naturalOrder.compare(new Integer(90),
				new Integer(90)));
   }

private static Comparator<Integer> naturalOrder =
				new Comparator<Integer>()  {
   public int compare(Integer first, Integer second)  {
	return first < second ? -1 : (first == second ? 0 :1);
   }
  };
}

Please note:
In this case, comparator for natural order on Integer is written for example only, and in practice there is no need to write it.

Looking forward for your answers dear readers

Resources:
Effective Java

More from Alexander Zagniotov:

  1. Brainteaser: ArrayList VS TreeSet
    When I came across the following example I did not expect the results that the program has printed hehe… Question:...
  2. Brainteaser: Hidden Iterators
    … While locking can prevent iterators from throwing ConcurrentMofdificationException, You have to remember to use locking everywhere a shared collection...
  3. Java Generics and Reflection
    Hi, the other day I had a situation, where in my code at run time I had to determine the...
  4. Hack any Java class using reflection attack
    Have you ever thought how secure your application is? Well reflection attack can demonstrate how vulnerable Java classes are. In...
  5. Bitwise Operation In Hibernate 3
    Hi all… i encountered a small problem in doing bitwise operations with hibernate. Until now, HIbernate 2 HQL parser has...