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-08-19:Kotlin中 Unit 类型的作用以及与Java中 Void 的区别? #124

Open
Moosphan opened this issue Aug 19, 2019 · 6 comments
Labels

Comments

@Moosphan
Copy link
Owner

No description provided.

@Jsondx
Copy link

Jsondx commented Aug 19, 2019

第一。

@dashuizhu
Copy link

第一。

绝对不意气用事。
第二,绝对不漏判任何一件坏事。
第三,绝对裁判的公正漂亮。

@yizems
Copy link

yizems commented Aug 21, 2019

@chenqi5256969
Copy link

1.在java中,必须指定返回类型,即void不能省略,但是在kotlin中,如果返回为unit,可以省略。
2.java中void为一个关键字,但是在kotlin中unit是一个类

@103style
Copy link

103style commented Sep 2, 2019

@dashuizhu 蜻蜓队长前来觐见

@xiaoyunfei
Copy link

Unit : Kotlin 中Any的子类, 方法的返回类型为Unit时,可以省略;
Void:Java中的方法无法回类型时使用,但是不能省略;
Nothing:任何类型的子类,编译器对其有优化,有一定的推导能力,另外其常常和抛出异常一起使用;

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

7 participants