クラス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?
}