title: Private constructor in Kotlin
body: <p>In Java it's possible to hide a class' main constructor by making it <code>private</code> and then accessing it via a <code>public</code> <code>static</code> method inside that class:</p>
  
  <pre><code>public final class Foo {
      /* Public static method */
      public static final Foo constructorA() {
          // do stuff
  
          return new Foo(someData);
      }
  
      private final Data someData;
  
      /* Main constructor */
      private Foo(final Data someData) {
          Objects.requireNonNull(someData);
  
          this.someData = someData;
      }
  
      // ...
  }
  </code></pre>
  
  <p>How can the same be reached with Kotlin without separating the class into a <code>public</code> interface and a <code>private</code> implementation? Making a constructor <code>private</code> leads to it not being accessible from outside the class, not even from the same file.</p>