2.funtions

来源:http://www.cnblogs.com/huiGod/archive/2017/05/21/6885018.html
-Advertisement-
Play Games

The most crucial distinguish between functional interface invoking and traditional method invoking is that transforming behavious or params it is.Howe ...


The most crucial distinguish between functional interface invoking and traditional method invoking is that transforming behavious or params it is.However,Transforming behavior is more encapsulated and abstract.The logic methods does not implement predicatbly.We can get any result while invoking method by transforming behavious.

Example of some crucial functional interface:

1. public interface Function<T, R> 

the mainly method:

/**
     * Applies this function to the given argument.
     *
     * @param t the function argument
     * @return the function result
     */
    R apply(T t);

ex:

 list.stream().map(item -> item.toUpperCase()).forEach(item -> System.out.println(item)); 

equals:

 list.stream().map(String::toUpperCase).forEach(System.out::println); 

In String class (invoke object is param):

 public String toUpperCase() { return toUpperCase(Locale.getDefault()); } 

In PrintStream(System.out) class:

 public void println(String x) { synchronized (this) { print(x); newLine(); } } 


And  public interface BiFunction<T, U, R> 
  /**
     * Applies this function to the given arguments.
     *
     * @param t the first function argument
     * @param u the second function argument
     * @return the function result
     */
    R apply(T t, U u);

Some functions that have the prefix of Bi is possessing two params and a result. 

 

2. public interface Consumer<T> 

the mainly method:

  /**
     * Performs this operation on the given argument.
     *
     * @param t the input argument
     */
    void accept(T t);

 

3. public interface Supplier<T> 

the mainly method:

/**
     * Gets a result.
     *
     * @return a result
     */
    T get();

 

And  public interface BinaryOperator<T> extends BiFunction<T,T,T>  

  /**
     * Returns a {@link BinaryOperator} which returns the lesser of two elements
     * according to the specified {@code Comparator}.
     *
     * @param <T> the type of the input arguments of the comparator
     * @param comparator a {@code Comparator} for comparing the two values
     * @return a {@code BinaryOperator} which returns the lesser of its operands,
     *         according to the supplied {@code Comparator}
     * @throws NullPointerException if the argument is null
     */
    public static <T> BinaryOperator<T> minBy(Comparator<? super T> comparator) {
        Objects.requireNonNull(comparator);
        return (a, b) -> comparator.compare(a, b) <= 0 ? a : b;
    }

 

4. public interface Predicate<T> 

  /**
     * Evaluates this predicate on the given argument.
     *
     * @param t the input argument
     * @return {@code true} if the input argument matches the predicate,
     * otherwise {@code false}
     */
    boolean test(T t);

ex:

stream().filter(item -> item>2)...


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 當客戶端訪問某個能開啟會話功能的資源,web伺服器就會創建一個HTTPSession對象,每個HTTPSession對象都會占用一定的記憶體,如果在同一個時間段內訪問的用戶太多,就會消耗大量的伺服器記憶體,為瞭解決這個問題我們使用一種技術:session的持久化。 什麼是session的持久化? 當客戶 ...
  • 1.request.getContextPath()詳解 <%=request.getContextPath()%>是為瞭解決相對路徑的問題,可返回站點的根路徑。 但不用也可以,比如<a href="<%=request.getContextPath()%>/catalog.jsp">,可以直接用< ...
  • 大家是不是都玩過保齡球?雖然水平很爛,但我是保齡球愛好者。今天這一題是用python來計算保齡球的分數。首先講一下保齡球的規則: 保齡球的一局稱為一個frame,一共有10局。 第1到9局,一般每局可以投擲(roll)兩次,但是有一個例外,就是第一次投擲就全中 - 這種情況稱為strike,打出st ...
  • 、 高級語言運行機制 高級語言按程式的執行方式分為編譯型和解釋型兩種。 java語言比較特殊,Java程式的執行必須經過先編譯後解釋的步驟。 1 編譯生成位元組碼,只面向JVM(.class) 2Jvm執行解釋 JVM:(Java virtual machine) java虛擬機負責解釋執行位元組碼文件 ...
  • 流迭代器 2017-05-21 17:05:51 流迭代器是標準模板庫STL中的,是類模板,流迭代器實例化之後即可以和任何接受對應迭代器的函數一起使用(可以將流看做一個容器,把數據存儲在一個連續的緩衝區中,具有迭代器的功能和類似使用)。 istream_iterator 和ostream_itera ...
  • 因為原文中延續了組合模式的代碼示例來講訪問者模式 所以這裡就合併一起來複習了。但主要還是講訪問者模式。顧名思義這個模式會有一個訪問者類(就像近期的熱播劇“人民的名義”中的檢查官,跑到到貪官家裡調查取證,查實後就定罪),被訪問者類調用訪問者類的時候會將自身傳遞給它使用。直接看代碼: //被訪問者基類 ...
  • 1.順序查找 在查找中我們一個一個順序的遍歷表中的所有鍵並使用equals()方法來查找匹配的鍵。 優點:對數組的結構沒有特定的要求,可以使用數組或者鏈表實現,演算法簡單。 缺點:當數組個數n較大時,效率低下。 時間複雜度:查找命中時,最大時間複雜度是O(n),最小時間複雜度是O(1),平均時間複雜度 ...
  • There is 4 method of the referenced method: Student class: StudentComparator class: Test:public class MethodReferenceTest { ...
一周排行
    -Advertisement-
    Play Games
  • 示例項目結構 在 Visual Studio 中創建一個 WinForms 應用程式後,項目結構如下所示: MyWinFormsApp/ │ ├───Properties/ │ └───Settings.settings │ ├───bin/ │ ├───Debug/ │ └───Release/ ...
  • [STAThread] 特性用於需要與 COM 組件交互的應用程式,尤其是依賴單線程模型(如 Windows Forms 應用程式)的組件。在 STA 模式下,線程擁有自己的消息迴圈,這對於處理用戶界面和某些 COM 組件是必要的。 [STAThread] static void Main(stri ...
  • 在WinForm中使用全局異常捕獲處理 在WinForm應用程式中,全局異常捕獲是確保程式穩定性的關鍵。通過在Program類的Main方法中設置全局異常處理,可以有效地捕獲並處理未預見的異常,從而避免程式崩潰。 註冊全局異常事件 [STAThread] static void Main() { / ...
  • 前言 給大家推薦一款開源的 Winform 控制項庫,可以幫助我們開發更加美觀、漂亮的 WinForm 界面。 項目介紹 SunnyUI.NET 是一個基於 .NET Framework 4.0+、.NET 6、.NET 7 和 .NET 8 的 WinForm 開源控制項庫,同時也提供了工具類庫、擴展 ...
  • 說明 該文章是屬於OverallAuth2.0系列文章,每周更新一篇該系列文章(從0到1完成系統開發)。 該系統文章,我會儘量說的非常詳細,做到不管新手、老手都能看懂。 說明:OverallAuth2.0 是一個簡單、易懂、功能強大的許可權+可視化流程管理系統。 有興趣的朋友,請關註我吧(*^▽^*) ...
  • 一、下載安裝 1.下載git 必須先下載並安裝git,再TortoiseGit下載安裝 git安裝參考教程:https://blog.csdn.net/mukes/article/details/115693833 2.TortoiseGit下載與安裝 TortoiseGit,Git客戶端,32/6 ...
  • 前言 在項目開發過程中,理解數據結構和演算法如同掌握蓋房子的秘訣。演算法不僅能幫助我們編寫高效、優質的代碼,還能解決項目中遇到的各種難題。 給大家推薦一個支持C#的開源免費、新手友好的數據結構與演算法入門教程:Hello演算法。 項目介紹 《Hello Algo》是一本開源免費、新手友好的數據結構與演算法入門 ...
  • 1.生成單個Proto.bat內容 @rem Copyright 2016, Google Inc. @rem All rights reserved. @rem @rem Redistribution and use in source and binary forms, with or with ...
  • 一:背景 1. 講故事 前段時間有位朋友找到我,說他的窗體程式在客戶這邊出現了卡死,讓我幫忙看下怎麼回事?dump也生成了,既然有dump了那就上 windbg 分析吧。 二:WinDbg 分析 1. 為什麼會卡死 窗體程式的卡死,入口門檻很低,後續往下分析就不一定了,不管怎麼說先用 !clrsta ...
  • 前言 人工智慧時代,人臉識別技術已成為安全驗證、身份識別和用戶交互的關鍵工具。 給大家推薦一款.NET 開源提供了強大的人臉識別 API,工具不僅易於集成,還具備高效處理能力。 本文將介紹一款如何利用這些API,為我們的項目添加智能識別的亮點。 項目介紹 GitHub 上擁有 1.2k 星標的 C# ...