Modifying object from function

Hi everyone!
I have some problems with my Java class. When I call function (for exmaple int getCapacity(Edge e)) it changes my object (chagne Edge e) and I don’t want to do that. Shouldn’t only void functions change objects? Any help?

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;

public void setStart(int s){
	this.start = s;

public static int getCapacity(Edge e){
	return e.capacity;

public static void main(String[] args){
	Edge e= new Edge();
    int k=getCapacity(e));




The return type of a function has no bearing on whether it can change arguments.

Passing by reference allows the function to change the arguments passed in to it. Classes are always passed by reference. You’ll have to make a copy yourself if you need a copy to work with.

… Unity doesn’t allow for Java, by the way. It’s Boo, Unityscript/‘Javascript’, or C#. Java’s a different thing than Javascript’s a different thing than Unityscript, just to prevent any confusion.