Lamdas en Java 8

package com.codemonkey; import static java.lang.System.out; public class TestLambda{ @FunctionalInterface interface MathOperation{ int opera(int a, int b); } public static void main(String[] args){ //Lambdas //Con tipo de declaración MathOperation addition = (int a,int b) -> a+b; //Sin tipo de declaración MathOperation substraction = (x,y) -> x-y; //Con return MathOperation multiplication = (m,n) ->{return m*n;}; MathOperation division = (c1,c2) ->{ if(c2 < 0){ return 0; }else{ return c1/c2; } }; out.println("\t****Lambdas****\n"); out.println("Suma: "+addition.opera(23,43)); out.println("Resta: "+substraction.opera(23,11)); out.println("Producto: "+multiplication.opera(34,3)); out.println("Division: "+division.opera(10,5)); } }
Ejemplo de lambdas en Java 8

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.