1 // Copyright 2006 The Android Open Source Project 2 3 import java.io.Serializable; 4 5 /** 6 * Test some instanceof stuff. 7 */ 8 public class InstanceTest { 9 public static void main(String[] args) { 10 System.out.println("instance begin"); 11 12 X x = new X(); 13 X[] xar = new X[1]; 14 X[][] xarar = new X[1][1]; 15 X[][][] xararar = new X[1][1][1]; 16 Y y = new Y(); 17 Y[] yar = new Y[1]; 18 Y[][] yarar = new Y[1][1]; 19 Y[][][] yararar = new Y[1][1][1]; 20 int[] iar = new int[1]; 21 int[][] iarar = new int[1][1]; 22 Object test; 23 24 test = x; 25 System.out.println("x instanceof X (true): " + (test instanceof X)); 26 System.out.println("x instanceof Y (false): " + (test instanceof Y)); 27 test = y; 28 System.out.println("y instanceof X (true): " + (test instanceof X)); 29 System.out.println("y instanceof Y (true): " + (test instanceof Y)); 30 31 test = xar; 32 System.out.println("xar instanceof Object (true): " 33 + (test instanceof Object)); 34 System.out.println("xar instanceof X (false): " 35 + (test instanceof X)); 36 System.out.println("xar instanceof X[] (true): " 37 + (test instanceof X[])); 38 System.out.println("xar instanceof Y[] (false): " 39 + (test instanceof Y[])); 40 System.out.println("xar instanceof Object[] (true): " 41 + (test instanceof Object[])); 42 System.out.println("xar instanceof X[][] (false): " 43 + (test instanceof X[][])); 44 test = yar; 45 System.out.println("yar instanceof X[] (true): " 46 + (test instanceof X[])); 47 48 test = xararar; 49 System.out.println("xararar instanceof Object (true): " 50 + (test instanceof Object)); 51 System.out.println("xararar instanceof Object[] (true): " 52 + (test instanceof Object[])); 53 System.out.println("xararar instanceof X (false): " 54 + (test instanceof X)); 55 System.out.println("xararar instanceof X[] (false): " 56 + (test instanceof X[])); 57 System.out.println("xararar instanceof X[][] (false): " 58 + (test instanceof X[][])); 59 System.out.println("xararar instanceof X[][][] (true): " 60 + (test instanceof X[][][])); 61 System.out.println("xararar instanceof Object[][][] (true): " 62 + (test instanceof Object[][][])); 63 64 System.out.println("xararar instanceof Serializable (true): " 65 + (test instanceof Serializable)); 66 System.out.println("xararar instanceof Serializable[] (true): " 67 + (test instanceof Serializable[])); 68 System.out.println("xararar instanceof Serializable[][] (true): " 69 + (test instanceof Serializable[][])); 70 System.out.println("xararar instanceof Serializable[][][] (false): " 71 + (test instanceof Serializable[][][])); 72 73 test = yararar; 74 System.out.println("yararar instanceof X[][][] (true): " 75 + (test instanceof X[][][])); 76 77 test = iar; 78 System.out.println("iar instanceof Object (true): " 79 + (test instanceof Object)); 80 System.out.println("iar instanceof Object[] (false): " 81 + (test instanceof Object[])); 82 83 test = iarar; 84 System.out.println("iarar instanceof Object (true): " 85 + (test instanceof Object)); 86 System.out.println("iarar instanceof Object[] (true): " 87 + (test instanceof Object[])); 88 System.out.println("iarar instanceof Object[][] (false): " 89 + (test instanceof Object[][])); 90 91 System.out.println("instanceof end"); 92 } 93 } 94