Scala 如何在代码中使用私有函数[mllib]?
我开始使用spark,特别是mllib库。一些函数在范围和私有语句中受到限制。如何在代码中使用这些函数? 例子: 斯卡拉角豆Scala 如何在代码中使用私有函数[mllib]?,scala,apache-spark,cluster-analysis,private,apache-spark-mllib,Scala,Apache Spark,Cluster Analysis,Private,Apache Spark Mllib,我开始使用spark,特别是mllib库。一些函数在范围和私有语句中受到限制。如何在代码中使用这些函数? 例子: 斯卡拉角豆 private[mllib] def pointCost( centers: TraversableOnce[BreezeVectorWithNorm], point: BreezeVectorWithNorm): Double = findClosest(centers, point)._2 如果我创建了一个扩展kmeans的类并尝试使
private[mllib] def pointCost(
centers: TraversableOnce[BreezeVectorWithNorm],
point: BreezeVectorWithNorm): Double =
findClosest(centers, point)._2
如果我创建了一个扩展kmeans的类并尝试使用这个函数,那么我将无法访问它。显示以下错误:
error: method MethodInClassKMeans in class KMeans cannot be accessed in myClass
有谁能给我举一些例子来说明如何避开这个问题吗?
感谢并问候如果您使用与要使用的类相同的名称空间,您可以访问私有[package]成员 但是这些方法之所以是包私有的,可能有一个很好的原因:该方法可能会在下一次发布时消失 因此,如果您需要一些小而孤立的代码,只要在许可证允许的情况下将代码复制到您的项目中即可