我正在使用一個私有庫。其中一個對象具有傳遞double或null的方法。雙重方法的空檢測
我怎麼能執行:
if (object.method != null) {
// do some numeric operations with the returned value
}
其他細節:
library = org.apache.commons.collections4.map
class = LRUmap
method = get
我的代碼是:
public class ExampleNode extends GeneralNode {
private LRUMap<Integer, Double> cache;
public ExampleNode() {
this.setCache(new LRUMap<Integer,Double>(100));
}
public void setCache(LRUMap<Integer, Double> lruMap) {
this.cache = lruMap;
}
public double getDatumCacheDebug(int llave){
return this.cache.get((Object)llave,false);
}
}
然後我打電話:
//outside ExampleNode
if (actualNode.getDatumCacheDebug(k) != null) {
Eclipse Neon3說:「運算符!=未定義爲參數類型(s)double,null。」
嗨,請顯示可返回double或null的方法的類型簽名。在Java中,不可能聲明一個可以返回'double'或'null'的方法。可以聲明一個返回一個'Double'的方法 - 它也可以返回一個'null'。但是你不會得到你聲明的返回一個'Double'的方法所描述的錯誤。 –
它應該是0,而不是空,因爲它是一個基本類型,而不是引用類型 – abcOfJavaAndCPP
哦~~ 庫= org.apache.commons.collections4.map 類= LRUmap 包含method = get –