blob: 3c3c21ad5003010e3e856cf60f6b67d821b1d32f [file] [log] [blame]
jeffhao5d1ac922011-09-29 17:41:15 -07001/*
Ian Rogers94c0e332012-01-18 22:11:47 -08002 * Copyright (C) 2012 The Android Open Source Project
jeffhao5d1ac922011-09-29 17:41:15 -07003 *
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 */
16
17/**
18 * test calling through an interface
19 */
20public class Main {
21 public static void main(String args[]) {
22 int result = 0;
23 Iface2Sub1 faceObj;
24 ImplA faceObj2;
25
26 faceObj = new ImplBSub();
27
28 result = faceObj.iFunc2(5);
29 System.out.print("ImplBSub intf: ");
30 System.out.println(result);
31
32 faceObj2 = new ImplA();
33 result = faceObj2.iFunc2(5);
34 System.out.print("ImplA: ");
35 System.out.println(result);
Ian Rogers94c0e332012-01-18 22:11:47 -080036
37 objectOverrideTests();
jeffhao5d1ac922011-09-29 17:41:15 -070038 }
Ian Rogers94c0e332012-01-18 22:11:47 -080039
40 static void check(boolean z) {
41 if (!z) {
42 throw new AssertionError();
43 }
44 }
45
46 static void objectOverrideTests() {
47 ObjectOverridingInterface o =
48 new ObjectOverridingInterface() {
49 public boolean equals(Object o) {
50 return true;
51 }
52 public int hashCode() {
53 return 0xC001D00D;
54 }
55 public String toString() {
56 return "Mallet's Mallet";
57 }
58 public int length() {
59 return toString().length();
60 }
61 public char charAt(int i) {
62 return toString().charAt(i);
63 }
64 public CharSequence subSequence(int s, int e) {
65 return toString().subSequence(s, e);
66 }
67 };
68 doObjectOverrideTests(o);
69 }
70 static void doObjectOverrideTests(ObjectOverridingInterface o) {
71 check(o.equals(null));
72 check(o.hashCode() == 0xC001D00D);
73 check(o.toString().equals("Mallet's Mallet"));
74 System.out.println("objectOverrideTests: SUCCESS");
75 }
jeffhao5d1ac922011-09-29 17:41:15 -070076}