什么是lambda expressions in java
2015-01-18 17:11
567 查看
1. lambda expressions are used primarily to define inline implementation
* of a functional interface i.e. an interface with a single method only.
*
* 2.Lambda expression elliminates the need of anonumous class and gives a
* very simple yet powerful functional programming capability to J***A.
* of a functional interface i.e. an interface with a single method only.
*
* 2.Lambda expression elliminates the need of anonumous class and gives a
* very simple yet powerful functional programming capability to J***A.
package com.github.jdk8; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.List; import com.google.common.collect.Lists; /** * @see http://www.tutorialspoint.com/java8/java8_quick_guide.htm * * 1. lambda expressions are used primarily to define inline implementation * of a functional interface i.e. an interface with a single method only. * * 2.Lambda expression elliminates the need of anonumous class and gives a * very simple yet powerful functional programming capability to J***A. * @author doctor * * @since 2015年1月18日 下午3:41:42 */ public class Java8Overview { public static void main(String[] args) { List<String> list = Lists.newArrayList("name", "doctor", "sex", "address"); List<String> arrayList = new ArrayList<>(list); // java8以前的排序 Collections.sort(arrayList, new Comparator<String>() { @Override public int compare(String o1, String o2) { return o1.compareTo(o2); } }); System.out.println(list); System.out.println(arrayList); List<String> arrayList2 = new ArrayList<>(list); // java8 函数式编程 Collections.sort(arrayList2, (a, b) -> a.compareTo(b)); System.out.println(arrayList2); // MathOperation add = (int a, int b) -> a + b; System.out.println(add.operation(5, 5)); System.out.println(operate(5, 5, add)); System.out.println(operate(5, 5, (a, b) -> a + b)); } private static interface MathOperation { int operation(int a, int b); } private static int operate(int a, int b, MathOperation operation) { return operation.operation(a, b); } }
相关文章推荐
- Lambda Expressions in Java 8
- How to Use Lambda Expressions in a Query
- Recursive Lambda Expressions in C#
- java框架spring中的opensessioninview有什么作用
- java框架spring中的opensessioninview有什么作用
- [转]java框架spring中的opensessioninview有什么作用
- thinking in java的private方法,但不知道这个有什么用
- JAVA 8 Lambda表达式-Lambda Expressions
- 什么是Java Plug-in
- Why do we need Lambda in Java?
- java 8之Lambda Expressions 解说
- java.lang.IncompatibleClassChangeError这是什么错误呀,拜托啦
- 《Thinking in Java 》学习笔记 --- Java内存分配,对象存放到什么地方?怎么放?
- Understand Lambda Expressions in 3 minutes
- Optimizing regular expressions in Java
- Optimizing regular expressions in Java
- Lambda Expressions in C++
- lambda in java 8
- Lambda in Java
- JAVA Lambda Expressions streams