欧美一级特黄大片做受成人-亚洲成人一区二区电影-激情熟女一区二区三区-日韩专区欧美专区国产专区

Java8Supplier接口和Consumer接口的用法

這篇文章主要講解了Java8 Supplier接口和Consumer接口的用法,內(nèi)容清晰明了,對(duì)此有興趣的小伙伴可以學(xué)習(xí)一下,相信大家閱讀完之后會(huì)有幫助。

創(chuàng)新互聯(lián)建站于2013年開始,我們提供高端網(wǎng)站建設(shè)、成都小程序開發(fā)、電商視覺設(shè)計(jì)、APP應(yīng)用開發(fā)及網(wǎng)絡(luò)營銷搜索優(yōu)化服務(wù),在傳統(tǒng)互聯(lián)網(wǎng)與移動(dòng)互聯(lián)網(wǎng)發(fā)展的背景下,我們堅(jiān)守著用標(biāo)準(zhǔn)的設(shè)計(jì)方案與技術(shù)開發(fā)實(shí)力作基礎(chǔ),以企業(yè)及品牌的互聯(lián)網(wǎng)商業(yè)目標(biāo)為核心,為客戶打造具商業(yè)價(jià)值與用戶體驗(yàn)的互聯(lián)網(wǎng)+產(chǎn)品。

Supplier接口

package java.util.function;
/**
 * Represents a supplier of results.
 *
 * <p>There is no requirement that a new or distinct result be returned each
 * time the supplier is invoked.
 *
 * <p>This is a <a href="package-summary.html" rel="external nofollow" rel="external nofollow" >functional interface</a>
 * whose functional method is {@link #get()}.
 *
 * @param <T> the type of results supplied by this supplier
 *
 * @since 1.8
 */
@FunctionalInterface
public interface Supplier<T> {
  /**
   * Gets a result.
   *
   * @return a result
   */
  T get();
}

supplier接口只有一個(gè)抽象方法get(),通過get方法產(chǎn)生一個(gè)T類型實(shí)例。

實(shí)例:

package me.yanand;
import java.util.function.Supplier;
public class TestSupplier {
  public static void main(String[] args) {
    Supplier<Apple> appleSupplier = Apple::new;
    System.out.println("--------");
    appleSupplier.get();
  }
}
class Apple{
  public Apple() {
    System.out.println("創(chuàng)建實(shí)例");
  }
}

Consumer接口

package java.util.function;
import java.util.Objects;
/**
 * Represents an operation that accepts a single input argument and returns no
 * result. Unlike most other functional interfaces, {@code Consumer} is expected
 * to operate via side-effects.
 *
 * <p>This is a <a href="package-summary.html" rel="external nofollow" rel="external nofollow" >functional interface</a>
 * whose functional method is {@link #accept(Object)}.
 *
 * @param <T> the type of the input to the operation
 *
 * @since 1.8
 */
@FunctionalInterface
public interface Consumer<T> {
  /**
   * Performs this operation on the given argument.
   *
   * @param t the input argument
   */
  void accept(T t);
  /**
   * Returns a composed {@code Consumer} that performs, in sequence, this
   * operation followed by the {@code after} operation. If performing either
   * operation throws an exception, it is relayed to the caller of the
   * composed operation. If performing this operation throws an exception,
   * the {@code after} operation will not be performed.
   *
   * @param after the operation to perform after this operation
   * @return a composed {@code Consumer} that performs in sequence this
   * operation followed by the {@code after} operation
   * @throws NullPointerException if {@code after} is null
   */
  default Consumer<T> andThen(Consumer<&#63; super T> after) {
    Objects.requireNonNull(after);
    return (T t) -> { accept(t); after.accept(t); };
  }
}

一個(gè)抽象方法accept(T t)定義了要執(zhí)行的具體操作;注意看andThen方法,接收Consumer<&#63; super T>類型參數(shù),返回一個(gè)lambda表達(dá)式,此表達(dá)式定義了新的執(zhí)行過程,先執(zhí)行當(dāng)前Consumer實(shí)例的accept方法,再執(zhí)行入?yún)鬟M(jìn)來的Consumer實(shí)例的accept方法,這兩個(gè)accept方法接收都是相同的入?yún)。

實(shí)例:

package me.yanand;
import java.util.function.Consumer;
public class TestConsumer {
  public static void main(String[] args) {
    Consumer<Integer> consumer = (t) -> {
      System.out.println(t*3);
    };
    Consumer<Integer> consumerAfter = (s) -> {
      System.out.println("之后執(zhí)行:"+s);
    };
    consumer.andThen(consumerAfter).accept(5);
  }
}

看完上述內(nèi)容,是不是對(duì)Java8 Supplier接口和Consumer接口的用法有進(jìn)一步的了解,如果還想學(xué)習(xí)更多內(nèi)容,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。

網(wǎng)站標(biāo)題:Java8Supplier接口和Consumer接口的用法
分享地址:http://www.aaarwkj.com/article18/gghpdp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供外貿(mào)網(wǎng)站建設(shè)、動(dòng)態(tài)網(wǎng)站、品牌網(wǎng)站設(shè)計(jì)、ChatGPT服務(wù)器托管、網(wǎng)頁設(shè)計(jì)公司

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

成都網(wǎng)站建設(shè)公司
欧美高清一区二区在线观看| 国产伦理在线观看一区二区| 日韩在线国产亚洲精品| 久久成人av一区二区三区| 未满十八禁在线观看免费| 欧美日韩一级特黄大片| 成人黄色18免费网站| 日韩在线一区中文字幕| 色婷婷久久综合中文久久| 日韩成人午夜视频在线| 一区二区三区高清人妻| 男人天堂插插综合搜索| 国产亚洲精品视频中文字幕| 97视频在线视频免费| 欧美精品国产精品久久| 日韩电影在线观看二区| 亚洲成人精品一区二区| 一区二区三区蜜桃av| 国产午夜福利视频合集| 日韩新片一区二区三区| 日韩精品一区二区视频| 欧美日韩亚洲一区在线| 亚洲欧美经典精品专区| 欧美精品在,欧美一区二区| 国产精品一区二区三区乱色| 国产激情在线四五区观看| av免费观看一区二区三区| 99久久偷拍美女大白屁股| 国产精品久久一国产精品| 日韩一级久久精品理论| 黄色欧美在线观看免费| 女人裸体网站无遮挡午夜| 九九视频在线观看免费专区| 欧美精品中出一区二区三区| 日日夜夜久久一二三区| 丁香六月色婷婷亚洲激情 | 欧美亚洲午夜一二综合| 国产精品一区二区av在线| 少妇被啪出水在线视频| 91麻豆精品国产久久久| 老熟妇奂伦一区二区三区|