跳至主要內容
  • Hostloc 空間訪問刷分
  • 售賣場
  • 廣告位
  • 賣站?

4563博客

全新的繁體中文 WordPress 網站
  • 首頁
  • 关于 kotlin 的内联函数
未分類
9 10 月 2020

关于 kotlin 的内联函数

关于 kotlin 的内联函数

資深大佬 : MakHoCheung 0

有 kotlin 大佬吗。由于 kotlin 要兼容 java6,无法用到 invokedynamic,所以才会有 inline 函数的存在,但是如果我的编译目标是 java8 以上的话,kotlin 编译器会优化成 invokedynamic 吗,这样就不用写 inline 函数了

大佬有話說 (3)

  • 主 資深大佬 : MakHoCheung

    You never need to use inline functions. (I believe) they are purely there for free performance optimizations to prevent extra object creation at runtime. It achieves this by essentially turning the function into a macro and copying that function wherever it’s used. Generally there’s no point unless it’s a higher order function. (And intelij will tell you this if you use it without need). Although I wouldn’t call myself super experienced with kotlin so I could just be spewing garbage.

    明明都说了有性能优化,老外的回答居然说不需要 inline 函数

  • 資深大佬 : SoloCompany

    inline 函数不仅仅是面向性能优化这么简单, 最重要的差别是 inline function 允许跳出当前控制流比如堆栈而普通函数不可以

    比如最典型的 let / run 可以用在任意地方, 可以 break / return, 和你所理解的 keyword 没有任何不同, 如果不是 inline 是不可能做到的

  • 主 資深大佬 : MakHoCheung

    @SoloCompany 受教了大神

文章導覽

上一篇文章
下一篇文章

AD

其他操作

  • 登入
  • 訂閱網站內容的資訊提供
  • 訂閱留言的資訊提供
  • WordPress.org 台灣繁體中文

51la

4563博客

全新的繁體中文 WordPress 網站
返回頂端
本站採用 WordPress 建置 | 佈景主題採用 GretaThemes 所設計的 Memory
4563博客
  • Hostloc 空間訪問刷分
  • 售賣場
  • 廣告位
  • 賣站?
在這裡新增小工具