我的 Java 类有一些问题。当我调用函数(例如 int getCapacity(Edge e))时,它会更改我的对象(chagne Edge e),我不想这样做。不应该只 void 函数改变对象吗?有什么帮助吗?
public class Edge{
private int start;
private int end;
private int capacity;
private int flow;
public Edge(int p, int k, int cap) {
this.start = p;
this.end = k;
this.capacity = cap;
this.flow=0;
}
public void setStart(int s){
this.start = s;
}
public static int getCapacity(Edge e){
e.setStart(-1);
return e.capacity;
}
public static void main(String[] args){
Edge e= new Edge();
int k=getCapacity(e));
e.print();
}
}
谢谢!