又返回值 将前面计算结果的的CompletableFuture传递给thenApply, 返回thenApply处理后的结果。 可以认为通过thenApply方法实现Completable

package com.cdkj.project.syn.common;

import java.util.concurrent.CompletableFuture;

/**  又返回值
 * 将前面计算结果的的CompletableFuture传递给thenApply,
 * 返回thenApply处理后的结果。
 * 可以认为通过thenApply方法实现CompletableFuture至CompletableFuture的转换。
 * 白话一点就是将CompletableFuture的计算结果作为thenApply方法的参数,返回thenApply方法处理后的结果
 */
public class ThenApplyTest {
    public static void main(String[] args) throws Exception {
        CompletableFuture result = CompletableFuture.supplyAsync(ThenApplyTest::randomInteger).thenApply((i) -> i * 8);
        System.out.println(result.get());
    }

    public static Integer randomInteger() {
        return 10;
    }
}

又返回值 将前面计算结果的的CompletableFuture传递给thenApply, 返回thenApply处理后的结果。 可以认为通过thenApply方法实现Completable_第1张图片

 

你可能感兴趣的:(java,开发语言)