【发布时间】:2010-12-13 16:51:23
【问题描述】:
对于匿名内部类,Java 如何处理在匿名内部类块之外声明的字段。
在policyOwnerModelObject的情况下,生成的匿名内部类中该字段是如何定义的?
// Local variable
final Bean policyOwnerModelObject = XXXXX <--- here, how is the class built with access to this object. Is it a final field in the class?
final WebMarkupContainer container = new WebMarkupContainer("container") {
@Override
public boolean isVisible() {
if ((policyOwnerModelObject.getPolicyOwner() != null) && (policyOwnerModelObject.getPolicyOwner().getValue() != null)) {
return !PolicyOwnerService.TRUST.equals(policyOwnerModelObject.getPolicyOwner().getValue());
} else {
return false;
}
}
};
====
好的,反编译了这个类,这就是我得到的:
class MyDataPanel$1 extends WebMarkupContainer
{
public boolean isVisible()
{
if(val$policyOwnerModelObject.getMy() != null && val$policyOwnerModelObject.getMy().getValue() != null)
return !"4".equals(val$policyOwnerModelObject.getMy().getValue());
else
return false;
}
final MyDataPanel this$0;
private final MyBean val$policyOwnerModelObject;
MyDataPanel$1(MyBean policyownerbean)
{
this$0 = final_policytrustpanel;
val$policyOwnerModelObject = policyownerbean;
super(String.this);
}
}
【问题讨论】:
-
这行我看不懂:
this$0 = final_policytrustpanel;final_policytrustpanel从哪里来? -
将外部
this视为封闭方法的局部final(即使内部类不是匿名的)。 -
我反编译了 ABC$1.class 文件。反编译器没有获得 final_policy 信任。我不知道那是什么。但是,我得到了答案。
标签: java inner-classes