时,到底会发生什么
public class Test {
public static void main(String[] args) {
try{
JTabbedPane tab = new JTabbedPane();
tab.removeChangeListener(null);
}catch(Exception e){
e.printStackTrace();
}
}
}
这不会导致NullPointerException
。
当我致电tab.removeChangeListener(null)
?
当我调用Tab.Removechangelistener(null)?
时,到底会发生什么
正是这样:
在 jtabbedpane 调用此方法:
public void removeChangeListener(ChangeListener l) {
listenerList.remove(ChangeListener.class, l);
}
listenerList
称为 protected EventListenerList listenerList = new EventListenerList();
删除方法是:
public synchronized <T extends EventListener> void remove(Class<T> t, T l) {
if (l ==null) {
// In an ideal world, we would do an assertion here
// to help developers know they are probably doing
// something wrong
return;
}
...
...
所以,删除零只是返回,而侦听器不受影响