2011-11-01 64 views
0
public void showTablet() { 
    for (Map.Entry<String, Tablet> entry : tableMap.entrySet()) {  
     //System.out.println(entry.getValue()); 
     System.out.println(entry.getPrice()); 
    } 
} 

在Tablet中有一個getPrice方法,但我無法獲取它?有什麼問題?無法訪問地圖中的對象的方法

回答

2

使用,

entry.getValue().getPrice() 

entry類型爲Map.Entry,你將有Tablet類的對象從entry.getValue()


請參見