Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2019-11-27:谈谈Kotlin中的Unit?它和Java中的void有什么区别? #198

Open
Moosphan opened this issue Nov 27, 2019 · 1 comment
Labels

Comments

@Moosphan
Copy link
Owner

No description provided.

@feelschaotic
Copy link

feelschaotic commented Dec 24, 2019

同:

  • 两者概念相似

异:

  • Unit 是一个类,继承自 Any 类,单例(目的在于函数返回 Unit 时避免分配内存)
  • 正因为 Unit 是一个普通的对象(这里指用 object 关键字定义的单例类型),所以可以调用它的 toString() 方法:结果一定是 "Kotlin.Unit"(源代码写死了)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants