Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 1 | // Copyright (c) 2017, the R8 project authors. Please see the AUTHORS file |
| 2 | // for details. All rights reserved. Use of this source code is governed by a |
| 3 | // BSD-style license that can be found in the LICENSE file. |
| 4 | package enclosingmethod; |
| 5 | |
| 6 | public class OuterClass { |
| 7 | public class AClass { |
| 8 | |
| 9 | } |
| 10 | |
| 11 | public void aMethod() { |
| 12 | class AnotherClass extends AbstractClass { |
| 13 | |
| 14 | @Override |
| 15 | public int anInt() { |
| 16 | return 48; |
| 17 | } |
| 18 | } |
| 19 | |
| 20 | print(new AbstractClass() { |
| 21 | @Override |
| 22 | public int anInt() { |
| 23 | return 42; |
| 24 | } |
| 25 | }); |
| 26 | print(new AnotherClass()); |
| 27 | } |
| 28 | |
| 29 | private static void print(AbstractClass anInstance) { |
| 30 | System.out.println(anInstance.anInt()); |
| 31 | System.out.println(anInstance.getClass().getEnclosingClass()); |
| 32 | System.out.println(anInstance.getClass().getEnclosingMethod()); |
| 33 | System.out.println(anInstance.getClass().isAnonymousClass()); |
| 34 | System.out.println(anInstance.getClass().isLocalClass()); |
| 35 | System.out.println(anInstance.getClass().isMemberClass()); |
| 36 | } |
| 37 | } |