我使用构造函数Calcu_weight将值赋给" weight"和" sumweight"。问题是,一旦我调用了Calcu_weight,它就会为权重和加权分配值,但是当我再次调用它时,权重和加权已经分配,这会影响第二个构造函数。 我想知道如何使用构造函数" Calcul_weight"很多时候,返回那两个TreeMap变量,但后面的变量不会影响以前的变量。
public class Calcul_weight {
private TreeMap<int[],Double> weight = new TreeMap<int[],Double>(new SerializableIntegerArrayKeyComparator());
private TreeMap <Integer,Double> sumweight = new TreeMap <Integer, Double>();
public Calcu_weight(int originID,int dest, Network network, Dijkstra dijkstra){
// calculate weight for links. network and dijkstra are another two constructors
}
public TreeMap<int[],Double> getWeight(){
return weight;
}
public TreeMap<Integer,Double> getSumweight(){
return sumweight;
}
答案 0 :(得分:1)
我猜您需要单身才能在同一weight
的不同实例之间保留sumweight
和Calcul_weight
。
您还必须重命名该课程Weight
或重命名Weight(...)
中的Calcul_weight(...)
函数才能成为正确的构造函数。)