blob: a8e8f4789b8231d978040c86080ada37c0045533 [file] [log] [blame]
Elliott Hughes2faa5f12012-01-30 14:42:07 -08001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
jeffhao5d1ac922011-09-29 17:41:15 -070016
17import java.io.Serializable;
18
19/**
20 * Test some instanceof stuff.
21 */
22public class InstanceTest {
23 public static void main(String[] args) {
24 System.out.println("instance begin");
25
26 X x = new X();
27 X[] xar = new X[1];
28 X[][] xarar = new X[1][1];
29 X[][][] xararar = new X[1][1][1];
30 Y y = new Y();
31 Y[] yar = new Y[1];
32 Y[][] yarar = new Y[1][1];
33 Y[][][] yararar = new Y[1][1][1];
34 int[] iar = new int[1];
35 int[][] iarar = new int[1][1];
36 Object test;
37
38 test = x;
39 System.out.println("x instanceof X (true): " + (test instanceof X));
40 System.out.println("x instanceof Y (false): " + (test instanceof Y));
41 test = y;
42 System.out.println("y instanceof X (true): " + (test instanceof X));
43 System.out.println("y instanceof Y (true): " + (test instanceof Y));
44
45 test = xar;
46 System.out.println("xar instanceof Object (true): "
47 + (test instanceof Object));
48 System.out.println("xar instanceof X (false): "
49 + (test instanceof X));
50 System.out.println("xar instanceof X[] (true): "
51 + (test instanceof X[]));
52 System.out.println("xar instanceof Y[] (false): "
53 + (test instanceof Y[]));
54 System.out.println("xar instanceof Object[] (true): "
55 + (test instanceof Object[]));
56 System.out.println("xar instanceof X[][] (false): "
57 + (test instanceof X[][]));
58 test = yar;
59 System.out.println("yar instanceof X[] (true): "
60 + (test instanceof X[]));
61
62 test = xararar;
63 System.out.println("xararar instanceof Object (true): "
64 + (test instanceof Object));
65 System.out.println("xararar instanceof Object[] (true): "
66 + (test instanceof Object[]));
67 System.out.println("xararar instanceof X (false): "
68 + (test instanceof X));
69 System.out.println("xararar instanceof X[] (false): "
70 + (test instanceof X[]));
71 System.out.println("xararar instanceof X[][] (false): "
72 + (test instanceof X[][]));
73 System.out.println("xararar instanceof X[][][] (true): "
74 + (test instanceof X[][][]));
75 System.out.println("xararar instanceof Object[][][] (true): "
76 + (test instanceof Object[][][]));
77
78 System.out.println("xararar instanceof Serializable (true): "
79 + (test instanceof Serializable));
80 System.out.println("xararar instanceof Serializable[] (true): "
81 + (test instanceof Serializable[]));
82 System.out.println("xararar instanceof Serializable[][] (true): "
83 + (test instanceof Serializable[][]));
84 System.out.println("xararar instanceof Serializable[][][] (false): "
85 + (test instanceof Serializable[][][]));
86
87 test = yararar;
88 System.out.println("yararar instanceof X[][][] (true): "
89 + (test instanceof X[][][]));
90
91 test = iar;
92 System.out.println("iar instanceof Object (true): "
93 + (test instanceof Object));
94 System.out.println("iar instanceof Object[] (false): "
95 + (test instanceof Object[]));
96
97 test = iarar;
98 System.out.println("iarar instanceof Object (true): "
99 + (test instanceof Object));
100 System.out.println("iarar instanceof Object[] (true): "
101 + (test instanceof Object[]));
102 System.out.println("iarar instanceof Object[][] (false): "
103 + (test instanceof Object[][]));
104
105 System.out.println("instanceof end");
106 }
107}