所以对于我的本地数据结构,我有以下
DataStructure ds = new DataStructure();
//Examples to put in the Data Structure "ds"
ds.menu_item.put("Pizza", new DescItems("A Pizza",2.50,4));
ds.menu_item.put("Hot Dog", new DescItems("A yummy hot dog",3.50, 3));
ds.menu_item.put("Corn Dog", new DescItems("A corny dog",3.00));
ds.menu_item.put("Unknown Dish", new DescItems(3.25));
DataStructure 类有一个 LinkedHashMap 实现,这样
LinkedHashMap<String, DescItems> menu_item = new LinkedHashMap<String, DescItems>();
最后 DescItems 类是
public final String itemDescription;
public final double itemPrice;
public final double itemRating;
public DescItems(String itemDescription, double itemPrice, double itemRating){
this.itemDescription = itemDescription;
this.itemPrice = itemPrice;
this.itemRating = itemRating;
}
还有其他构造函数可以解释没有 itemDescription 和/或 itemRating
我正在尝试应用一种方法来检查一个值是否有 itemRating 不是 0(0 表示没有评级)
但具体来说,我遇到了这个问题:
DescItems getC1 = (DescItems)ds.menu_item.get("Pizza");
System.out.println(getC1.toString());
仅打印出参考信息,例如 DescItems@142D091
我应该怎么做才能获取特定的对象变量而不是引用该对象?