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

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://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毛片| 日本高清精品视频在线| 日本人妻成人免费大片| 亚洲国产日韩精品欧美| 日韩欧美亚洲一区二区| 国产日产亚洲欧美综合另类| 九九re久久这里有精品| 日本黄色三级三级三级| 欧美亚洲精品一区在线观看| 国产91精品激烈高潮白浆| 国产国产精品人在线观看 | 东京一区二区三区四区黄片| 国产伦精品二区三区视频 | 狠狠综爱五月天的婷婷| 国产国语激情对白在线| 精品一二三区在线天堂| 91久久亚洲综合精品日本| 亚州欧美精品一区二区| 亚洲精品女同专区视频| 亚洲码欧洲码一二三区| 成人精品国产一区二区| 日韩精品毛片在线看| 一区二区三区四区毛片| 欧美午夜福利在线视频| 免费毛片一区二区三区| 五月天色婷婷亚洲综合一区| 国产视频三级在线观看| 日本 影院 一区 二区| 熟妇人妻精品一区二区| 中文字幕av一区二区人妻| 国产精品福利午夜在线| 日本一区二区三区久久久| 欧美日韩在线亚洲二区综二| 亚洲精品视频久久免费| 最新亚洲国产高清激情| 久久精品国产一区电影| 麻豆久久精品国产亚洲精品超碰热| 熟女人妻视频一区二区| 青青草免费在线视频视频| 一区二区精品人妻av| 国产自拍精品视频免费观看|