我有这样的代码:
class MyClass{
final ArrayList<Thread> list= new ArrayList<>();
for(int i=0;i<N;i++)
new Thread(()->{
//more instructions...
list.remove(this);
}).start();
}
问题是关于Intellij显示的警告,指示list.remove(list);
告诉我:ArrayList<Thread> may not contains objects of type MyClass
是Intellij的错误分析,还是我的方案中的this
关键字引用了封闭的类MyClass
?
提前感谢
[this
指的是MyClass
实例。
这是因为您使用的是lambda表达式,它本身不具有this
上下文。