Suppose that you have the following classes which are perfectly legal in Java.
class Ping {
Pong value;
Ping(Pong value) { this.value = value; }
}
class Pong {
Ping value;
Pong(Ping value) { this.value = value; }
}
Is there any way to create an instance of Pong or Ping without giving their constructors a NULL value?
You could use something like this
Sadly this seems to be bad practice as described here: Java leaking this in constructor. So a better implementation would be to assign Pong after the creation of Ping.