title: how to extend (or proxy) a scala class with private constructor
body: <p>I'm trying to extends, or proxy, the org.apache.spark.ml.clustering.KMeans class, such that K=1 is authorized.</p>
  
  <pre><code>class K1Means extends Estimator{
  
      final val kmeans = new KMeans()
      val k = 1
  
      override def setK(value:Int) {
          if(value &gt;1){
              this.kmeans.setK(value)
          }
      }
  
      override def fit(dataset: DataFrame): KMeansModel = { 
          if(this.k == 1){
              /* super specific to my case */
              val avg_sample = Vectors.zeros(
                  dataset
                  .select("scaledFeatures")
                  .take(1)(0)(0)  // first row
                  .asInstanceOf[DenseVector]  // was of type Any
                  .size
              ) // with the scaling the average value of each column is 0
              var centers_local = Array(avg_sample)
              return new KMeansModel(centers_local)
          }
          else{
              return this.kmeans.fit(dataset)
          }
      }
  // every method then calls this.kmeans.method()
  }
  </code></pre>
  
  <p>I've tried this, but <code>new KMeansModel(centers_local)</code> is not authorized, since KMeansModel has a private constructor.
  Here is the error message: </p>
  
  <p><code>constructor KMeansModel in class KMeansModel cannot be accessed in class K1Means</code></p>
  
  <p>I also tried to extend KMeansModel, so I can create my own and return it :</p>
  
  <pre><code>class K1MeansModel(centers: Array[DenseVector]) extends KMeansModel{}
  </code></pre>
  
  <p>But it also fails: <code>constructor KMeansModel in class KMeansModel cannot be accessed in class K1MeansModel</code></p>