title: What properties are guaranteed by constructors in Java?
body: <p>I used to think that, intuitively speaking, a constructor in Java is the thing that makes an object, and that nothing can touch that object until its constructor returns. However, I have been proven wrong about this over and over again:</p>
  
  <ol>
  <li>uninitialized objects can be leaked by sharing <code>this</code></li>
  <li><a href="http://www.ibm.com/developerworks/library/j-fv/" rel="nofollow noreferrer">uninitialized objects can be leaked by a subclass accessing it from the finalizer</a></li>
  <li><a href="https://stackoverflow.com/questions/16178020/uninitialized-object-leaked-to-another-thread-despite-no-code-explicitly-leaking">uninitialized objects can be leaked to another thread before they're fully constructed</a></li>
  </ol>
  
  <p>All of these facts violate my intuition of what I thought a constructor is.</p>
  
  <p>I can no longer with confidence say what a constructor actually does in Java, or what it's meant to be used for. If I'm making a simple DTO with <em>all final fields</em>, then I can understand what the use of the constructor is, because this is exactly the same as a struct in C except it can't be modified. Other than that, I have no clue what constructors can be reliably used for in Java. Are they just a convention/syntactic sugar? (i.e If there were only factories that initialize objects for you, you would only have <code>X x = new X()</code>, then modify each field in <code>x</code> to make them have non default values - given the 3 facts above, this would be almost equivalent to how Java actually is)</p>
  
  <p>I can name two properties that are actually guaranteed by constructors: If I do <code>X x = new X()</code>, then I know that <code>x</code> is an instance of <code>X</code> but not a subclass of <code>X</code>, and its final fields are fully initialized. You might be tempted to say that you know that constructor of <code>X</code> finished and you have a valid object, but this is untrue if you pass <code>X</code> to another thread - <a href="https://stackoverflow.com/questions/16178020/uninitialized-object-leaked-to-another-thread-despite-no-code-explicitly-leaking">the other thread may see the uninitialized version</a> (i.e what you just said is no different than the guarantees of calling a factory). What other properties do constructors actually guarantee?</p>