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 5 public class DebugLambda { 6 7 interface I { getInt()8 int getInt(); 9 } 10 printInt(I i)11 private static void printInt(I i) { 12 System.out.println(i.getInt()); 13 } 14 testLambda(int i, int j)15 public static void testLambda(int i, int j) { 16 printInt(() -> i + j); 17 } 18 printInt2(I i)19 private static void printInt2(I i) { 20 System.out.println(i.getInt()); 21 } 22 testLambdaWithMethodReference()23 public static void testLambdaWithMethodReference() { 24 printInt2(DebugLambda::returnOne); 25 } 26 returnOne()27 private static int returnOne() { 28 return 1; 29 } 30 printInt3(BinaryOpInterface i, int a, int b)31 private static void printInt3(BinaryOpInterface i, int a, int b) { 32 System.out.println(i.binaryOp(a, b)); 33 } 34 testLambdaWithArguments(int i, int j)35 public static void testLambdaWithArguments(int i, int j) { 36 printInt3((a, b) -> { 37 return a + b; 38 }, i, j); 39 } 40 41 interface ObjectProvider { foo(String a, String b, String c)42 Object foo(String a, String b, String c); 43 } 44 testLambdaWithMethodReferenceAndConversion(ObjectProvider objectProvider)45 private static void testLambdaWithMethodReferenceAndConversion(ObjectProvider objectProvider) { 46 System.out.println(objectProvider.foo("A", "B", "C")); 47 } 48 main(String[] args)49 public static void main(String[] args) { 50 DebugLambda.testLambda(5, 10); 51 DebugLambda.testLambdaWithArguments(5, 10); 52 DebugLambda.testLambdaWithMethodReference(); 53 DebugLambda.testLambdaWithMethodReferenceAndConversion(DebugLambda::concatObjects); 54 } 55 concatObjects(Object... objects)56 private static Object concatObjects(Object... objects) { 57 StringBuilder sb = new StringBuilder(); 58 for (Object o : objects) { 59 sb.append(o.toString()); 60 } 61 return sb.toString(); 62 } 63 64 interface BinaryOpInterface { binaryOp(int a, int b)65 int binaryOp(int a, int b); 66 } 67 } 68