-
Notifications
You must be signed in to change notification settings - Fork 779
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-07:请举例说明Kotlin中with与apply函数的应用场景和区别? #116
Comments
看源码知区别,为了方便我只使用apply和let这两个函数,从来不用with,因为不能防空 |
with:with函数会把它的第一个参数装换成作为第二个参数传给它的lambda的接收者,可以通过this来访问这个接收者。with返回的是执行lambda代码的结果。 |
|
apply:返回自身用this代指 |
with:适用于调用同一个类的多个方法时,可以省去类名重复,直接调用;类的方法即可。 apply:具有with的功能,并且可以判空,同时返回对象本身 |
|
No description provided.
The text was updated successfully, but these errors were encountered: