blob: f014507576340973c0d8509f267e27e83b104425 [file] [log] [blame]
clementbera0fe940d2019-04-23 12:45:18 +02001// Copyright (c) 2019, 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
clementberabe19d302019-05-23 17:23:21 +02005package nesthostexample;
clementbera0fe940d2019-04-23 12:45:18 +02006
7public class BasicNestHostWithAnonymousInnerClass {
8
9 private String method() {
10 return "hostMethod";
11 }
12
13 private static String staticMethod() {
14 return "staticHostMethod";
15 }
16
17 private String field = "field";
18 private static String staticField = "staticField";
19
20 public static InterfaceForAnonymousClass createAnonymousNestedInstance() {
21 return new InterfaceForAnonymousClass() {
22 public String accessOuter(BasicNestHostWithAnonymousInnerClass o) {
23 return o.field
24 + o.staticField
25 + BasicNestHostWithAnonymousInnerClass.staticField
26 + o.method()
27 + o.staticMethod()
28 + BasicNestHostWithAnonymousInnerClass.staticMethod();
29 }
30 };
31 }
32
33 public interface InterfaceForAnonymousClass {
34 String accessOuter(BasicNestHostWithAnonymousInnerClass o);
35 }
36
37 public static void main(String[] args) {
38 BasicNestHostWithAnonymousInnerClass outer = new BasicNestHostWithAnonymousInnerClass();
39 InterfaceForAnonymousClass anonymousInner =
40 BasicNestHostWithAnonymousInnerClass.createAnonymousNestedInstance();
41 System.out.println(anonymousInner.accessOuter(outer));
42 }
43}