假设我有以下Scala的API,这是我打算从Scala和Java调用:斯卡拉API设计的Java兼容性
sealed abstract class InterpMethod
case object InterpLinear extends InterpMethod
case object InterpNearest extends InterpMethod
case object InterpSpline extends InterpMethod
class Interpolator {
def interp(method: InterpMethod) = method match {
case InterpLinear => { ... }
case InterpNearest => { ... }
case InterpSpline => { ... }
}
}
object Interpolator { def apply() = new Interpolator }
// Scala Usage:
import myPackage._
Interpolator.interp(InterpNearest)
// Java Usage:
import myPackage.*
Interpolator myInterp = new Interpolator()
myInterp.interp(InterpNearest)
在斯卡拉的伟大工程。 Java抛出编译错误:InterpNearest cannot be resolved to a variable
有没有简单的解决方法?或者更好的定义更友好的Java参数的方法?将参数定义为闭包会更好吗?
任何最佳实践或解决方法,将不胜感激。这旨在成为较大的fluent interface的一部分。我的关键标准是它需要在Java和Scala中可用并且干净。
也许给我们一个如何在Java中使用它的例子? – mepcotterell 2013-05-02 13:56:22
设计一个干净的Java接口,用Scala实现它,然后添加Scala风格的扩展 – millimoose 2013-05-02 14:06:25