I have always understood Java to pass parameters by value. I have some code that I cannot seem to debug. Here's a simplified version:
private isFinished = false;
private int target, count;
public Example(int target){
this.target = target;
}
public void doProcess(int x){
count += x;
}
public boolean isFinished(){
if(x < target){
return false;
} else {
return true;
}
}
private Example example;
public Test(Example e){
this.example = e;
}
public isFinished(){
return e.isFinished();
}
public void doProcess(){
e.doProcess(3);
}
private Example example;
public Generate(Example e){
this.example = e;
}
public void generate(int num){
for(int y=0; y < num; y++){
Test t = new Test(example);
while(t.isFinished == false){
t.doProcess();
}
}
}
The Generate class takes an Example as the argument. It uses this Example and passes it to "Test". What's happening is that when Generate.generate() is called, the first iteration works properly, but at each iteration a new Test is supposed to be made with the example being passed as a parameter. The 'example' appears to be getting altered when doProcess() is called, when what I want is for a fresh Test to be created each time using the same Example that was passed to Generate when it was created.