Skip to content

Instantly share code, notes, and snippets.

@tw-Frey
Created July 14, 2022 08:58
Show Gist options
  • Select an option

  • Save tw-Frey/49ed882d501f592ea8f99a0e682aa2f5 to your computer and use it in GitHub Desktop.

Select an option

Save tw-Frey/49ed882d501f592ea8f99a0e682aa2f5 to your computer and use it in GitHub Desktop.
Kotlin 同名接口 的真相

MicrosoftTeams-image (33)

其實他是一個trick

官方有提到一個同名的類似例子

https://kotlinlang.org/docs/coding-conventions.html#function-names

MicrosoftTeams-image (34)

其他地方(包括Kotlin language specification)沒有講同名情境

(但他真的是一個trick...所以不值得一提)


同名接口的真相

kt檔 裡的 top-level function

實際上(在JVM) 這樣的 top-level function

是包覆在某個Class裡

因此就能避開名字的混淆(ambiguous)

@tw-Frey
Copy link
Copy Markdown
Author

tw-Frey commented Jul 14, 2022

Kotlin同名接口的真相(1)

@tw-Frey
Copy link
Copy Markdown
Author

tw-Frey commented Jul 14, 2022

Kotlin同名接口的真相(2)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment