在签名为返回 int 的方法中返回 null?
public int pollDecrementHigherKey(int x) {
int savedKey, savedValue;
if (this.higherKey(x) == null) {
return null; // COMPILE-TIME ERROR
}
else if (this.get(this.higherKey(x)) > 1) {
savedKey = this.higherKey(x);
savedValue = this.get(this.higherKey(x)) - 1;
this.remove(savedKey);
this.put(savedKey, savedValue);
return savedKey;
}
else {
savedKey = this.higherKey(x);
this.remove(savedKey);
return savedKey;
}
}
该方法位于作为TreeMap扩展的类中,如果这有任何区别...任何想法为什么我不能在这里返回空值?