Scala API design for Java compatibility -
suppose have following scala api, plan call both scala , 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)
works great in scala. java throws compile error: interpnearest cannot resolved variable
is there easy fix? or better way of defining parameters more java friendly? better define parameters closures?
any best practices or workarounds appreciated. intended part of larger fluent interface. key criteria needs usable , clean in both java , scala.
http://lampwww.epfl.ch/~michelou/scala/using-scala-from-java.html says can call objects this:
iterpnearest$.module$
it's not nice. guess should go @millimoose's suggestion.
Comments
Post a Comment