Can I refer to an object in its constructor?

Posted by Roman on Stack Overflow See other posts from Stack Overflow or by Roman
Published on 2010-04-21T14:22:16Z Indexed on 2010/04/21 14:33 UTC
Read the original article Hit count: 214

Filed under:
|
|
|

Can I do the following?

public Manager(String userName) {
    game = new Game(userName);
    game.addManager(this);
}

The problem is that I refer to an object (this) in its constructor (before it was actually created).

© Stack Overflow or respective owner

Related posts about java

Related posts about constructor