我有以下课程:
public abstract class Map {
protected PriorityQueue<Node> openNodes;
}
我的实现目前是这样工作的:
public Map() {
PriorityQueue<Node> openNodes = new PriorityQueue<Node>((Node node1, Node node2) -> Integer.compare(node1.getFinalCost(), node2.getFinalCost()));
}
但是,我也想使用这样的实现:
public Map() {
PriorityQueue<Node> openNodes = new PriorityQueue<Node>((Node node1, Node node2) -> Integer.compare(node1.getHeuristicCost(), node2.getHeuristicCost()));
}
有没有办法将我的 Node 类的heuristicCost或finalCost字段传递给构造函数来实现这些不同的行为?像这样的东西:
public Map(*fieldName*) {
PriorityQueue<Node> openNodes = new PriorityQueue<Node>((Node node1, Node node2) -> Integer.compare(node1.get*fieldName*(), node2.get*fieldName*()));
}
如果没有,您能否提出一个解决方案来实现这一目标?