Skip to content

Instantly share code, notes, and snippets.

@ujhelyiz
Forked from bergmanngabor/IntLongWat.java
Created May 22, 2012 20:02

Revisions

  1. ujhelyiz revised this gist May 22, 2012. 1 changed file with 16 additions and 7 deletions.
    23 changes: 16 additions & 7 deletions IntLongWat.java
    Original file line number Diff line number Diff line change
    @@ -2,18 +2,27 @@ public class IntLongWat {

    public static void main(String[] args) {

    System.out.println(new Integer(1).equals(1)); // true
    System.out.println(new Long(1).equals(1)); // false, it only equals 1L - so much for semantic equivalence
    System.out.println(new Integer(1).equals(new Long(1))); // false... Y U NO EQUAL?
    System.out.println(new Integer(1).equals(1));
    // true
    System.out.println(new Long(1).equals(1));
    // false, it only equals 1L - so much for semantic equivalence
    System.out.println(new Integer(1).equals(new Long(1)));
    // false... Y U NO EQUAL?

    // although
    System.out.println(new Integer(1) == 1); // true
    System.out.println(new Long(1) == 1); // true... WAT? they are == but not equals() ?
    System.out.println(new Integer(1) == 1);
    // true
    System.out.println(new Long(1) == 1);
    // true... WAT? they are == but not equals() ?

    // so then, transitively...
    // System.out.println(new Integer(1) == new Long(1)); // COMPILE ERROR... CLEVER BASTARD
    // System.out.println(new Integer(1) == new Long(1));
    // COMPILE ERROR... CLEVER BASTARD

    Object oInt = new Integer(1);
    Object oLong = new Long(1);
    System.out.println(oInt == oLong); // false, of course - so much for transitivity
    System.out.println(oInt == oLong);
    // false, of course - so much for transitivity
    }

    }
  2. @bergmanngabor bergmanngabor revised this gist May 19, 2012. 1 changed file with 14 additions and 14 deletions.
    28 changes: 14 additions & 14 deletions IntLongWat.java
    Original file line number Diff line number Diff line change
    @@ -1,19 +1,19 @@
    public class IntLongWat {

    public static void main(String[] args) {
    public static void main(String[] args) {

    System.out.println(new Integer(1).equals(1)); // true
    System.out.println(new Long(1).equals(1)); // false, it only equals 1L - so much for semantic equivalence
    System.out.println(new Integer(1).equals(new Long(1))); // false... Y U NO EQUAL?

    System.out.println(new Integer(1).equals(1)); // true
    System.out.println(new Long(1).equals(1)); // false, it only equals 1L - so much for semantic equivalence
    System.out.println(new Integer(1).equals(new Long(1))); // false... Y U NO EQUAL?

    // although
    System.out.println(new Integer(1) == 1); // true
    System.out.println(new Long(1) == 1); // true... WAT? they are == but not equals() ?
    // so then, transitively...
    // System.out.println(new Integer(1) == new Long(1)); // COMPILE ERROR... CLEVER BASTARD
    Object oInt = new Integer(1);
    Object oLong = new Long(1);
    System.out.println(oInt == oLong); // false, of course - so much for transitivity
    }
    // although
    System.out.println(new Integer(1) == 1); // true
    System.out.println(new Long(1) == 1); // true... WAT? they are == but not equals() ?
    // so then, transitively...
    // System.out.println(new Integer(1) == new Long(1)); // COMPILE ERROR... CLEVER BASTARD
    Object oInt = new Integer(1);
    Object oLong = new Long(1);
    System.out.println(oInt == oLong); // false, of course - so much for transitivity
    }

    }
  3. @bergmanngabor bergmanngabor created this gist May 19, 2012.
    19 changes: 19 additions & 0 deletions IntLongWat.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    public class IntLongWat {

    public static void main(String[] args) {

    System.out.println(new Integer(1).equals(1)); // true
    System.out.println(new Long(1).equals(1)); // false, it only equals 1L - so much for semantic equivalence
    System.out.println(new Integer(1).equals(new Long(1))); // false... Y U NO EQUAL?

    // although
    System.out.println(new Integer(1) == 1); // true
    System.out.println(new Long(1) == 1); // true... WAT? they are == but not equals() ?
    // so then, transitively...
    // System.out.println(new Integer(1) == new Long(1)); // COMPILE ERROR... CLEVER BASTARD
    Object oInt = new Integer(1);
    Object oLong = new Long(1);
    System.out.println(oInt == oLong); // false, of course - so much for transitivity
    }

    }