logo
  • 教程列表
  • SO官方文檔
  • 關閉
    • 閉包含隱式引數
    • 用顯式引數關閉
    • 使用隱式接收器關閉具有自定義目標的方法呼叫
    • 用方法包裝閉包周圍的行為
    • 建立分配給屬性和呼叫的閉包
    • 將方法轉換為閉包
  1. StackOverflow 文件
  2. groovy 教程
  3. 關閉
  4. 將方法轉換為閉包

將方法轉換為閉包

Created: November-22, 2018

可以使用 & 運算子將方法轉換為閉包。

def add(def a, def b) { a + b }    

Closure addClosure = this.&add
assert this.add(4, 5) == addClosure(4, 5)
  • 建立分配給屬性和呼叫的閉包

Copyright © 2018. All right reserved

tastones.com 备案号:鲁ICP备18045372号-1

  • 關於本站
  • 免責聲明