blob: f3166fd35b79bfab7b16145998f45a268e73a79e [file] [log] [blame]
Nicolas Geoffray0d8db992014-11-11 14:40:10 +00001/*
2 * Copyright (C) 2014 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 */
16
17import java.lang.reflect.Method;
18
19public class Main {
20 static class A {
21 public int foo() { return 1; }
22 }
23
24 static class B extends A {
25 public int $opt$bar() { return super.foo(); }
26 }
27
28 static class C extends B {
29 public int foo() { return 42; }
30 }
31
32 static class D extends C {
33 }
34
35 static void assertEquals(int expected, int value) {
36 if (expected != value) {
37 throw new Error("Expected " + expected + ", got " + value);
38 }
39 }
40
41 public static void main(String[] args) throws Exception {
Nicolas Geoffray1ed097d2014-11-13 15:15:39 +000042 // Workaround for b/18051191.
43 System.out.println("Test started");
Nicolas Geoffray0d8db992014-11-11 14:40:10 +000044 assertEquals(1, new B().$opt$bar());
45 assertEquals(1, new C().$opt$bar());
46 assertEquals(1, new D().$opt$bar());
47
48 Class<?> c = Class.forName("InvokeSuper");
49 Method m = c.getMethod("run");
50 assertEquals(42, ((Integer)m.invoke(c.newInstance(), new Object[0])).intValue());
51
52 c = Class.forName("SubClass");
53 assertEquals(42, ((Integer)m.invoke(c.newInstance(), new Object[0])).intValue());
54 }
55}