//匿名内部类:
Runnable r = new Runnable() {
@Override
public void run() {
}
};
//改写成 lambda 表达式:
Runnable r = new Runnable(()->{});
无法通过编译,提示“'Runnable' is abstract; cannot be instantiated”
请问问题出在哪,非常感谢~
1
nthin0 2021-03-26 18:11:37 +08:00 1
Runnable r = () -> {};
|
2
lithium148 OP @nthin0 谢谢大佬,但是为啥不用写 new runnable()啊
|
3
ninjachen 2021-03-26 19:32:11 +08:00
因为它不是 lambda 表达式
|
4
brust 2021-03-27 14:30:15 +08:00
Runnable r = ()->{};
Thread t = new Thread(new Runnable() { @Override public void run() { } }); Thread t = new Thread(()->{}); |
5
uselessVisitor 2021-03-29 10:41:25 +08:00
不用加 new 了吧 ()->{}就是 new 了
|