我最近一直在浏览与JavaFX图表相关的源代码,我遇到了以下方法:
/**
* This should be called from seriesRemoved() when you are finished with any animation for deleting the series from
* the chart. It will remove the series from showing up in the Iterator returned by getDisplayedSeriesIterator().
*
* @param series The series to remove
*/
protected final void removeSeriesFromDisplay(Series<X, Y> series) {
if (series != null) series.setToRemove = false;
series.setChart(null);
displayedSeries.remove(series);
}
如果传入的系列为空,则无需进行调用series.setChart(null);
,如果系列为空,则会导致NullPointerException
。鉴于该方法受到保护并因此对子类可见,if语句是否应该包含围绕整个方法的括号?基本上:
/**
* This should be called from seriesRemoved() when you are finished with any animation for deleting the series from
* the chart. It will remove the series from showing up in the Iterator returned by getDisplayedSeriesIterator().
*
* @param series The series to remove
*/
protected final void removeSeriesFromDisplay(Series<X, Y> series) {
if (series != null) {
series.setToRemove = false;
series.setChart(null);
}
displayedSeries.remove(series);
}
鉴于OpenJFX作者比我更好的程序员,我犹豫是否将此报告为一个错误,特别是考虑到我没有设置这样做(通过他们的JIRA系统或他们的邮件列表,我想问一下在我让自己难堪之前,比我更有知识渊博的人!)