Newstrong's 博客

Kratos
专注于用户阅读体验的响应式博客主题
  1. 首页
  2. Android
  3. 正文

Kotlin 操作符:run、with、let、also、apply 的差异与选择

2020年5月14日 5点热度 0人点赞 0条评论

Kotlin 操作符:run、with、let、also、apply 的差异与选择

原文:Kotlin 操作符:run、with、let、also、apply 的差异与选择

通过参考原文,通过mermaid画出流程图,没有任何新东西。/笑脸

graph TD
  A(选择标准函数) --> B{"return this" }
  subgraph subB ["需要返回自身(this)"]
        B
        %%noteA["需要返回自身(this)"]
    end
  B -->|NO| C{"T.block()"}
  subgraph subC["需要扩展函数?(空检查,链式调用)"]
        C
        %%noteC[" "]
    end
  C -->|NO| D{"传递this作为参数"}
  D -->|NO| E("使用run()")
  D -->|YES| F("使用with(T)")
  C -->|YES| G{"传递it/this作为参数"}
  G -->|传递this| H("使用T.run()")
  G -->|传递it| I("使用T.let()")
  B -->|YES| J{"block(it or this)"}
    subgraph subJ["传递it/this作为参数"]
        J
       %% noteJ[" "]
    end
  J-->|传递this| K("使用T.apply()")
  J-->|传递it| L("使用T.also()")
  style A font-size:14px
  style B extends A,font-size:10px
标签: kotlin
最后更新:2026年6月22日

newstrong

这个人很懒,什么都没留下

点赞
下一篇 >

文章评论

razz evil exclaim smile redface biggrin eek confused idea lol mad twisted rolleyes wink cool arrow neutral cry mrgreen drooling persevering
取消回复

归档

  • 2026 年 6 月
  • 2026 年 1 月
  • 2025 年 3 月
  • 2024 年 10 月
  • 2024 年 9 月
  • 2024 年 8 月
  • 2021 年 4 月
  • 2020 年 5 月

分类

  • Android
  • git
  • 性能优化
  • 未分类

COPYRIGHT © 2026 Newstrong's 博客. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang