问题描述:

I was wondering if it is possible to convert an instance of one to and instance of the other. If so, then how would I do it? I haven't found any mention of this in the akka-http docs.

I am trying to write a class that implements a Java interface that returns the base route of a akka-http application, but internally I want to implement the class in Scala.

网友答案:

javadsl.server.Route is actually implemented by an adapter wrapping a scaladsl.server.Route (the concrete class is called RouteAdapter). You can move around between the two by doing

val scalaRoute = get { complete("OK") } // akka.http.scaladsl.server.Route

val javaRoute = RouteAdapter(scalaRoute) // extends akka.http.javadsl.server.Route

val backToScalaRoute = RouteAdapter(scalaRoute).delegate // akka.http.scaladsl.server.Route
相关阅读:
Top