Java8新特性之lambda表达式

2021-07-12 16:05

阅读:424

标签:count()   stl   count   oid   对象   pack   ram   junit   setname   

简介

Java8带来的新特性之一Lambda表达式,又称之为函数式编程,核心思想是将面向对象中的传递对象变为传递行为

语法

expression = (variable) -> anction
eg: int sum = (x,y) ->x+y;

  • variable:相当于一个变量,可以有多个
  • action:代码逻辑部分,可以是一行也可以是一个代码段
package com.jdk8;

public class Student {


    private String name;
    private String city;
    private int age;
    private String sex;


    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

}
package com.jdk8;

public interface TestInterface {

    Boolean test(T param);
}

package com.jdk8;

import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

public class TesFunction {

    @Test
    public void testLambda(){
    
     
        //3.有参,有返回值
        func((Integer x)->{
            System.out.println("Hello,world"+x);
            return true;
        });
        //
        List stuList = new ArrayList();
        for(int i = 0 ;i  student.getCity().equals("China"))).count();
        System.out.println(cout);

    }
    private void func(TestInterface functionInterface){
        int x =1;
        functionInterface.test(x);
    }
}

Java8新特性之lambda表达式

标签:count()   stl   count   oid   对象   pack   ram   junit   setname   

原文地址:https://www.cnblogs.com/gosun/p/9545335.html


评论


亲,登录后才可以留言!