public class Apple
{
private boolean isJuicy;
private boolean isRipe;
public Apple(boolean isJuicy)
{
isJuicy = isJuicy;
}
public void setRipe(boolean ripe)
{
this.isRipe = ripe;
}
public boolean isRipe()
{
return this.isRipe;
}
}
In Spring I have two service classes AppleService
& FruitService
.
AppleService
public Apple createApple(boolean isJuicy)
{
Apple apple = null;
apple = new Apple(isJuicy);
fruitService.saveApple(apple);
log("ripe:" + apple.isRipe()); // false
return apple;
}
FruitService
public void saveApple(Apple apple)
{
if(apple.isJuicy())
apple.setRipe(true);
persist(apple);
log("ripe:" + apple.isRipe()); // true
}
Why is the Apple reported as being ripe in the FruitService
but not in the AppleService
?
I thought the fact that it is passed by reference to the FruitService
guarantees that the same object and object properties should be present in the apple
object in the AppleService?