blob: 621ae07767d9fad77044ad522e436afa31f3363b [file] [log] [blame]
Christoffer Quist Adamsene4945262018-06-20 10:45:33 +02001// Copyright (c) 2018, 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
5package classmerging;
6
7public class LambdaRewritingTest {
8
9 public static void main(String[] args) {
10 Interface obj = new InterfaceImpl();
11
12 // Leads to an invoke-custom instruction that mentions the type of `obj` since it is captured.
13 invoke(() -> obj.foo());
Ian Zernyb3a72992020-01-22 10:12:03 +010014
15 FunctionImpl functionImpl = new FunctionImpl();
16 if (System.currentTimeMillis() < 0) {
17 System.out.println(functionImpl);
18 }
Christoffer Quist Adamsene4945262018-06-20 10:45:33 +020019 }
20
Ian Zernyb3a72992020-01-22 10:12:03 +010021 @NeverInline
Christoffer Quist Adamsene4945262018-06-20 10:45:33 +020022 private static void invoke(Function f) {
23 f.accept();
24 }
25
Ian Zernyb3a72992020-01-22 10:12:03 +010026 // Cannot be merged as it has two subtypes: FunctionImpl and a lambda.
Christoffer Quist Adamsene4945262018-06-20 10:45:33 +020027 public interface Function {
28
29 void accept();
30 }
31
Christoffer Quist Adamsen943db6e2018-06-25 12:43:18 +020032 public static class FunctionImpl implements Function {
33
34 @Override
35 public void accept() {
36 System.out.println("In FunctionImpl.accept()");
37 }
38 }
39
Christoffer Quist Adamsene4945262018-06-20 10:45:33 +020040 // Will be merged into InterfaceImpl.
41 public interface Interface {
42
43 void foo();
44 }
45
46 public static class InterfaceImpl implements Interface {
47
48 @Override
49 public void foo() {
50 System.out.println("In InterfaceImpl.foo()");
51 }
52 }
53}