public class Test { static int x,y; static Integer w,z; public static void main(String args[]) { x = 10; // y = new Integer(10); エラー // w = 20; // エラーになる. z = new Integer(20); y = x + z.intValue(); System.out.println("( " + x + " , " + y + " )" ); } }
public class Equivalence { public static void main(String[] args) { Integer n1 = new Integer(100); Integer n2 = new Integer(100); System.out.println(n1 == n2); System.out.println(n1 != n2); } }
public class EqualsMethod { public static void main(String[] args) { Integer n1 = new Integer(100); Integer n2 = new Integer(100); System.out.println(n1.equals(n2)); } }
class Value { int i; } public class EqualsMethod2 { public static void main(String[] args) { Value v1 = new Value(); Value v2 = new Value(); v1.i = v2.i = 100; System.out.println(v1.equals(v2)); } }