That should do it.
String s = new spark.RecordServiceContext("safa").recordServiceTextFile("dsf");
I changed the signatures, though.
My Scala class is as follows:
object spark { implicit class RecordServiceContext(ctx: String) { def recordServiceTextFile(path: String) : String = { "test" } } }
My java class looks like this:
public class TestScalaCall { public static void main(String args[]){ String s = new spark.RecordServiceContext("safa").recordServiceTextFile("dsf"); } }
Change ---
So, a quick look at the Scala change requests shows us this .
They actually work on creating a class defined in the package object , in the same way as defining it in a regular package . But this is for release not yet 2.12 .
Thus, the recommendation they give is only absolutely necessary classes / objects that do not need external interaction inside the package objects. Otherwise, save them in regular packages. Therefore, for now, you do not need to use the package object construct.
In addition, you should consider: "Does it make sense to define something that is accessible externally inside the package object?"
source share