Although this is legal Java, and in the case where you are describing (where is the last line of the constructor), this is a pretty safe thing (with some exceptions in the case of an exception), since practice is a bad thing to do, and like using goto (in languages ββthat support keyword) it should be something you think long and hard about. For your case, it would be best practice to make the constructor private, remove the addManager call, and set the static factory method:
public static Manager createManager(String userName) { Manager manager = new Manager(userName); manager.game.addManager(manager); return manager; }
I should also point out that such interdependence between classes (the manager knows about the game and the game knows about the manager) is certainly a smell of code, and I would be just as concerned about the need for this as I would to pass this from the constructor.
source share