我正在审查一些代码.在该代码中有一个事件监听器的构造函数,类似于以下代码:
public class MyClass implements ActionListener {
SomeOtherClass m_oc;
public MyClass(SomeOtherClass oc) {
if (null == oc) {
throw new IllegalArgumentException("oc cannot be null");
}
m_oc = oc;
m_oc.getClass();
}
@Override
public void actionPerformed(ActionEvent e) {
do_stuff();
}
private void do_stuff() {
/* some more code here, but this code never uses m_oc */
}
}
Run Code Online (Sandbox Code Playgroud)
现在,我的问题是:为什么谁会编写这个代码调用m_oc.getClass()?
除了构造函数中的该位置之外m_oc,该对象()SomeOtherClass不是代码中的任何位置.