Skip to content

2019-09-12:你觉得Kotlin与Java混合开发时需要注意哪些问题? #146

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

Open
Moosphan opened this issue Sep 12, 2019 · 4 comments

Comments

@Moosphan
Copy link
Owner

No description provided.

@Reginer
Copy link

Reginer commented Sep 16, 2019

尽量不用java调用Kotlin

@xiongliang120
Copy link

1: Kotlin 默认是非null 类型,java 返回 null,kotlin 需要添加? 表示可为null
2: kotlin 使用!! 时,要确认变量不为null, 不然会直接抛异常

@scsfwgy
Copy link

scsfwgy commented Sep 26, 2019

说一个最大的坑,kotlin调用Java的方法或者属性,不能推断出是否为空,除非加上空或者非空注解。

@wj576038874
Copy link

kotlin调用java的时候 如果java返回值可能为null 那就必须加上@nullable 否则kotlin无法识别,也就不会强制你做非空处理,一旦java返回了null 那么必定会出现null指针异常,加上@nullable注解之后kotlin就能识别到java方法可能会返回null,编译器就能会知道,并且强制你做非null处理,这也就是kotlin的空安全

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

No branches or pull requests

5 participants