这里是JDK Bug系统条目,介绍这一新的警告——:https://bugs. openjdk.org/browse/JDK-8299995。
短篇故事,this-einski
预警,警告你,如果子级能够@ Override
a means that is also calls in the Superclass Constructionor.
这样做是危险的,因为压倒了建筑商使用的一种方法,使得子级在子类初始化过程中无意地引入ug。 如果这一方法取决于尚未建立起来的国家,因为我们仍在超级建筑中? 毕竟,在要求超级建筑商之前,你不能在子楼做任何事情(。
有一些办法可以纠正这种情况。
只有在建筑商中使用不能压倒一切的方法。
加入:
http://www.un.org/Depts/DGACM/index_chinese.htm
- Basically, quit being lazy and be explicit with what you need. Don t just pass in your God object -- pass in only the specific attributes you need.
请注意,这些规则可追溯适用。 当你在建筑商中使用一种方法时,这种方法不仅必须“不可再利用”,而且该方法通过<条码>的<条/条码>进入必须<><><>>>>>>>>符合上述一条规则。 如果您的顶级方法不能压倒一切,但其内部的方法之一是,而且该方法在范围上有<条码>,则在汇编时,你将收到<条码>这一代名列/代码错误。 这里就是一个例子。
import javax.swing.*;
public class GUI
{
private final JFrame frame;
public GUI()
{
this.frame = new JFrame();
this.frame.add(this.createBottomPanel());
}
//final! Does that mean we are safe?
final JPanel createBottomPanel()
{
final JButton save = new JButton();
save
.addActionListener
(
/*
* No. We get the warning here at the start of this lambda.
* The reason is because we have given this lambda the
* ability to call this.toString(), and we don t know when
* it will do that. Maybe now, maybe later. But if it does
* it now, then we could end up doing things before the
* object is fully created. And if that were to happen, then
* that would be a this-escape. So, the warning occurs here,
* to let you know that it is possible.
*/
actionEvent ->
{
this.toString();
}
)
;
return null;
}
}