A级
Class A {
public HashMap <Integer,Double> myHashMap;
public A(){
myHashMap = new HashMap()
}
}
B类
Class B {
private A anInstanceOfA;
public B(A a) {
this.anInstanceOfA = a;
}
aMethod(){
anInstanceOfA.myHashMap.get(1); <--getting hashmap value for key = 1
//proceed to use this value, but instead of storing it to a variable
// I use anInstanceOfA.myHashMap.get(1) each time I need that value.
}
在aMethod()
我anInstanceOfA.myHashMap.get(1)
用来获取key = 1
. 我多次这样做,我想知道多次使用或只是将其分配给变量并多次使用分配的变量aMethod()
之间是否存在效率差异。anInstanceOfA.myHashMap.get(1)
IE
aMethod(){
theValue = anInstanceOfA.myHashMap.get(1);
//proceed to use theValue in my calculations. Is there a difference in efficiency?
}