public Neocortex(Region rootRegion, ConnectionInterface functor) {
this.rootRegion = rootRegion;
this.currentRegion = this.rootRegion;
this.functor = functor;
}
嘿,上面我有我的一个类的构造函数。我的问题是我应该向构造函数添加空指针异常还是没有必要?老实说,我只是不明白什么时候应该在我的代码中添加异常。但在这种情况下,我应该使用哪个构造函数?
public Neocortex(Region rootRegion, ConnectionInterface functor) {
if (rootRegion == null) {
throw new NullPointerException("rootRegion cannot be null");
} else if (functor == null) {
throw new NullPointerException("functor cannot be null");
}
this.rootRegion = rootRegion;
this.currentRegion = this.rootRegion;
this.functor = functor;
}