Skip to content

Scala code called from java with Play!

peterszatmary edited this page Feb 26, 2016 · 2 revisions

Scala code called from java with Play!

Scala

package core.scala

class ScalaExample {
    def helloWorld(message : String) : String = {
      return "Hello " + message + " from scala in Java.";
    }
}

Controller method

public Result scala() {
        ScalaExample sc = new ScalaExample();
        String helloFromScalaInJava = sc.helloWorld("Senacor");
        return ok(helloFromScalaInJava);
    }

Routes

GET         /scala    @controllers.Application.scala()

Result

Scala in Java