AE 2020 6月最新版及全套插件

https://www.52pojie.cn/thread-1216454-1-1.html

package com.example.lambdademo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
 * Lambda表达式
 * 面向过程程序语言:参数传递是基本类型的变量
 * 面向对象语言
 * - 传递基本类型的变量
 * - 传递对象变量
 * 传递方法/代码块(函数式程序语言设计)
 * - 刚开始,Java为了简单性,一致性,拒绝此功能
 * - 为了市场和技术的需要,Java8开始,支持此项功能,提出Java的Lambda表达式实现
 *
 * - 类似于匿名方法,一个没有名字的方法
 * - 参数,箭头,表达式语句
 * - 可以忽略写参数类型
 * - 坚决不声明返回值类型
 * - 没有public/protected/private/static/final等修饰符
 * - 单句表达式,将直接返回值,不用大括号
 * - 带return语句,算多句,必须用大括号
 *
 * - 如果有返回值,返回值类型会在上下文推断出来的,无需声明
 * - 只在某几个分支有返回值,这样是不合法的
 *
 * 函数式接口
 * - 是一个接口,符合java接口的定义
 * - 只包含一个抽象方法的接口
 * - 可以包括其他的default方法,static方法,private方法
 * - 由于只有一个未实现的方法,所以Lambda表达式可以自动填上这个尚未实现的方法
 * - 采用Lambda表达式,可以自动创建出一个(伪)嵌套类的对象(没有实际的嵌套类class文件产生),
 * 然后使用,比真正嵌套类更加轻量,更加简洁高效
 *
 * - 只带有一个未实现的方法,内容简单
 * - 大量重复性的函数式接口,使得源码膨胀
 * 系统自带的函数式接口
 * - 涵盖大部分常用的功能,可以重复使用
 * - 位于java.util.function包中
 *
 * 系统自带的函数式接口(部分常用)
 * Predicate<T> 返回值Boolean
 * Consumer<T> 返回值void
 * Function<T,R> 返回值R
 * Supplier<T> 返回值T
 *
 *
 *
 *
 */
@SpringBootApplication
public class LambdaDemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(LambdaDemoApplication.class, args);
    }

}

package com.example.lambdademo.consumer;

import java.util.function.Consumer;

/**
 * 函数式接口Consumer,一次性操作,无返回
 */
public class ConsumerDemo {

    public static void main(String[] args) {
        String[] planets = new String[]{
                "Mercury", "Venus", "Earth", "Mars",
                "Jupiter", "Saturn", "Uranus", "Neptune"
        };
        Consumer<String> printer = s ->
                System.out.println("Planet : " + s);

        for (String p : planets) {
            printer.accept(p);
        }
    }
}

package com.example.lambdademo.demo1;

import java.util.Arrays;

public class LambdaDemo1 {

    public static void main(String[] args) {
        String[] planets = new String[]{
                "Mercury","Venus","Earth","Mars",
                "Jupiter","Saturn","Uranus","Neptune"
        };
        System.out.println("使用Lambda,长度从小到大");
        Arrays.sort(planets,(first,second)->(first.length()-second.length()));
        System.out.println(Arrays.toString(planets));
        System.out.println("不使用Lambda,是按照字母顺序排序");
        Arrays.sort(planets);
        System.out.println(Arrays.toString(planets));
        System.out.println("使用Lambda,长度从大到小");
        Arrays.sort(planets,(first,second)->(-1)*(first.length()-second.length()));
        System.out.println(Arrays.toString(planets));

    }
}

package com.example.lambdademo.function;

import java.util.function.Function;

/**
 * 函数式接口Function(函数),接收一个参数,返回一个参数
 */
public class FunctionDemo {

    public static void main(String[] args) {
        String[] planets = new String[]{
                "Mercury", "Venus", "Earth", "Mars",
                "Jupiter", "Saturn", "Uranus", "Neptune"
        };
        Function<String, String> upper = s -> s.toUpperCase();
            //可以做更复杂操作
//            return s.toUpperCase();
//        };
        for (String p : planets) {
            System.out.println(upper.apply(p));
        }

        Function<String, Integer> getLen = s -> s.length();
        for (String p : planets) {
            System.out.println(getLen.apply(p));
        }

    }
}

package com.example.lambdademo.predicate;

import java.util.function.Predicate;

/**
 * 函数式接口Predicate 有断言的意思,返回boolean
 */
public class PredicateDemo {

    public static void main(String[] args) {
        String[] planets = new String[]{
                "Mercury", "Venus", "Earth", "Mars",
                "Jupiter", "Saturn", "Uranus", "Neptune"
        };
        Predicate<String> oddLength = s ->
                s.length() % 2 == 0 ? false : true;

        for (String p : planets) {
            if (oddLength.test(p)) {
                System.out.println("=====奇数=====" + p + "," + p.length());
            } else {
                System.out.println("=====偶数=====" + p + "," + p.length());
            }
        }
    }
}

package com.example.lambdademo.supplier;

import java.util.function.Supplier;

import static java.lang.Math.floor;
import static java.lang.Math.random;

/**
 * 函数式接口Supplier(供应者),无输入参数,返回一个数据
 */
public class SupplierDemo {

    public static void main(String[] args) {
        String[] planets = new String[]{
                "Mercury", "Venus", "Earth", "Mars",
                "Jupiter", "Saturn", "Uranus", "Neptune"
        };
        Supplier<String> planetFactory = () ->
                planets[(int) floor(random() * 8)];

        for (int i = 0; i < 5; i++) {
            System.out.println(planetFactory.get());
        }
    }
}

原文地址:https://www.cnblogs.com/ukzq/p/13285223.html