标签:lambda ret returns lin div rnn system func function
@FunctionalInterface public interface LambdaNoneReturnNoneParameter { void test(); } @FunctionalInterface public interface LambdaNoneReturnSingleParameter { void test(int a); } @FunctionalInterface public interface LambdaNoneReturnMultipleParameter { void test(int a , int b); } @FunctionalInterface public interface LambdaSingleReturnNoneParameter { int test(); } @FunctionalInterface public interface LambdaSingleReturnSingleParameter { int test(int a); } @FunctionalInterface public interface LambdaSingleReturnMultipleParameter { int test(int a , int b); }
public class Syntax1 { public static void main(String[] args) { /** * Lambda的本质 : 匿名函数 * 函数的结构 : 方法名,参数,方法体 * Lambda的结构 : 参数,方法体 () -> {} * ‘->‘ lambda运算符, 读作 goes to **/ //无返回值,无参数 LambdaNoneReturnNoneParameter lambdaNoneReturnNoneParameter = () -> { System.out.println("lambda 1"); }; lambdaNoneReturnNoneParameter.test(); //无返回值,单个参数 LambdaNoneReturnSingleParameter lambdaNoneReturnSingleParameter = (int a) -> { System.out.println("lambda 2"); System.out.println("parameter :"+a); }; lambdaNoneReturnSingleParameter.test(10); //无返回值, 多个参数 LambdaNoneReturnMultipleParameter lambdaNoneReturnNoneParameter1 = (int a , int b) -> { System.out.println("lambda 3"); System.out.println("Sum :" +(a+b)); }; lambdaNoneReturnNoneParameter1.test(10,20); //有返回值,无参数 LambdaSingleReturnNoneParameter lambdaSingleReturnNoneParameter = () -> { return 100; }; int result1 = lambdaSingleReturnNoneParameter.test(); System.out.println(result1); //有返回值, 单个参数 LambdaSingleReturnSingleParameter lambdaSingleReturnSingleParameter = (int a) -> { return a%2; }; int result2 = lambdaSingleReturnSingleParameter.test(13); System.out.println(result2); //有返回值,多个参数 LambdaSingleReturnMultipleParameter lambdaSingleReturnMultipleParameter = (int a ,int b) -> { return a + b; }; int result3 = lambdaSingleReturnMultipleParameter.test(10, 50); System.out.println(result3); } }
标签:lambda ret returns lin div rnn system func function
原文地址:https://www.cnblogs.com/shansm/p/12547546.html