如何从其他 类 调用数据结构
How to Call Data structure from other classes
我想从另一个 classes 调用数据结构,但我发现这里有问题,
你能帮帮我吗?
这里是源代码
数据结构来自class SimBetWithFairRouting
public Map<DTNHost, ArrayList<Double>> neighborsHistory;
我将在这个方法中从 class NeighbourhoodSimilarity
调用它
private double countDirectSimilarity(double[][] matrixEgoNetwork, int index) {
double sim=0;
for (int i = 0; i < matrixEgoNetwork.length; i++) {
//here the problem
if (matrixEgoNetwork[i][0]==this.countAggrIntStrength(*i will call it in here*) && matrixEgoNetwork[i][index]==1) {
sim++;
}
}
return sim;
}
有什么方法可以在不将地图更改为静态形式的情况下完成这项工作?
线索:在 class SimBetWithFairRouting 中有复制方法,你能帮我吗?
首先导入 SimBetWithFairRouting class 所在的包。
然后将该地图 (neighborsHistory) 设为静态。
要访问该地图,您可以使用
SimBetWithFairRouting.neighborsHistory
这是 (ClassName.MapName)
要访问地图,您必须将 class 导入到您编写方法的 class 中。要在不创建实例的情况下访问它,您必须将其设为静态。
private double countDirectSimilarity(double[][] matrixEgoNetwork, int index) {
double sim=0;
for (int i = 0; i < matrixEgoNetwork.length; i++) {
if (matrixEgoNetwork[i][0]==this.countAggrIntStrength(SimBetWithFairRouting.neighborsHistory) && matrixEgoNetwork[i][index]==1) {
sim++;
}
}
return sim;
}
使地图静态化
public static Map<DTNHost, ArrayList<Double>> neighborsHistory;
从 NeighbourhoodSimilarity 扩展 SimBetWithFairRouting class 还可以让您访问 neighborsHistory(如果 SimBetWithFairRouting class 不是最终的)。
我想从另一个 classes 调用数据结构,但我发现这里有问题, 你能帮帮我吗?
这里是源代码
数据结构来自class SimBetWithFairRouting
public Map<DTNHost, ArrayList<Double>> neighborsHistory;
我将在这个方法中从 class NeighbourhoodSimilarity
调用它private double countDirectSimilarity(double[][] matrixEgoNetwork, int index) {
double sim=0;
for (int i = 0; i < matrixEgoNetwork.length; i++) {
//here the problem
if (matrixEgoNetwork[i][0]==this.countAggrIntStrength(*i will call it in here*) && matrixEgoNetwork[i][index]==1) {
sim++;
}
}
return sim;
}
有什么方法可以在不将地图更改为静态形式的情况下完成这项工作? 线索:在 class SimBetWithFairRouting 中有复制方法,你能帮我吗?
首先导入 SimBetWithFairRouting class 所在的包。 然后将该地图 (neighborsHistory) 设为静态。
要访问该地图,您可以使用
SimBetWithFairRouting.neighborsHistory
这是 (ClassName.MapName)
要访问地图,您必须将 class 导入到您编写方法的 class 中。要在不创建实例的情况下访问它,您必须将其设为静态。
private double countDirectSimilarity(double[][] matrixEgoNetwork, int index) {
double sim=0;
for (int i = 0; i < matrixEgoNetwork.length; i++) {
if (matrixEgoNetwork[i][0]==this.countAggrIntStrength(SimBetWithFairRouting.neighborsHistory) && matrixEgoNetwork[i][index]==1) {
sim++;
}
}
return sim;
}
使地图静态化
public static Map<DTNHost, ArrayList<Double>> neighborsHistory;
从 NeighbourhoodSimilarity 扩展 SimBetWithFairRouting class 还可以让您访问 neighborsHistory(如果 SimBetWithFairRouting class 不是最终的)。