title: Is there a way for an object to reference itself inside its constructor in java?
body: <p>The explanation is simpler with a code:</p>
  <pre><code>public class Main {
      public static void main (String[] args) throws java.lang.Exception {
          A newObjectA = new A(new B(newObjectA));
      }
      class A{
          A(B b){
              //constructor code...
          }
      }
      class B{
          A refernceToA;
          B(A a){
              this.refernceToA = a;
              //constructor code...
          }
      }
  }
  </code></pre>
  <p>For this I got the following error:</p>
  <p><code>The local variable newObjectA may not have been initialized</code></p>
  <p>My solution right now is to simply make 1 more method besides the constructor, e.g. setB(), but I would like to now if the is a way to overcome this.</p>