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

2020-01-02:分别通过对象表达式object和lambda表达式实现的函数式接口内部有何不同? #224

Open
Moosphan opened this issue Jan 2, 2020 · 6 comments
Labels

Comments

@Moosphan
Copy link
Owner

Moosphan commented Jan 2, 2020

No description provided.

@Moosphan Moosphan added the Kotlin label Jan 2, 2020
@EightMinuteYouth
Copy link

好像没有大致的区别,lambda只支持一个函数体而object可以是多个,还有一个区别就是以闭包的形式实现lambda还可以传递某个方法的作用域

@zhaoerlei1989
Copy link

没有感觉有多大区别,或者我没有那么熟悉

@JianhuaWan
Copy link

写setOnclickLister 和setOnItemClickLisernter就很明显了,lambda适用于一个回调的场景

@renzhenming
Copy link

1.object是匿名内部类的形式,匿名内部类是在编译后形成一个class
2.Lambda表达式是在程序运行的时候动态生成class

@Empty0Qc
Copy link

Empty0Qc commented Aug 1, 2022 via email

@yizems
Copy link

yizems commented Aug 1, 2022

有区别, 区别很小
如果是使用 Object 继承的话, 会编译为匿名内部类, 和Java的并无区别

image

但是如果是 使用 lambda 的话, 实现代码会保留在原类中, 编译成的匿名内部类是 一个中转类, 类似于Java8, 也可能是跟我使用的 目标版本是 java8 相关
image

image
image

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