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の拡張であるクラス内にあります。違いがあれば、ここでnullを返すことはできません。シグネチャがreturn intを返すメソッドでnullを返しますか?
'null'は' int'ではないので、 –
どのような言語ですか?より多くのタグを追加pls。 Afaikのみvoid関数はnullを返すことができます。そうでなければ、0または-1が返されます。言語に応じて 'return void';を試してください。 – DanFromGermany
Russel、それは言語に依存しますが、いずれにせよ、答えを回答として投稿して、私たちが望む方向に投票できるようにしてください。 –