为什么类 PropertyChangeSupport 中的方法 firePropertyChange (String propertyName, Object oldValue, Object newValue) 不检查旧值和新值是否可以同时为 null?
最佳答案
PropertyChangeEvent javadoc可能会提供一些线索:
Null values may be provided for the old and the new values if their true values are not known.
An event source may send a null object as the name to indicate that an arbitrary set of if its properties have changed. In this case the old and new values should also be null.
所以看起来 oldValue==null
和 newValue==null
在 source==null
时也有一些特殊的含义.因此,当两个值都为 null
时,可能希望始终传播更改,即使它们相同也是如此。
关于java - java中的触发事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8192832/