`val handler: Handler = { req, res -> res.body(...
# getting-started
k
val handler: Handler = { req, res -> res.body("Hello") }
Is it bad practice? To declare lambdas? No, it's perfectly fine.
t
kingsley: that works with the java version, but if i convert the interface to kotlin:
Copy code
@FunctionalInterface
@Throws(Exception::class)
fun handle(request: Request, response: Response)
i need to add a constructor in order to do that
i'm not sure how smart the conversion tool is
k
Yes. Kotlin interfaces are not SAM capable. You'd need use a functional type with typealias instead to achieve the same
typealias Handler = (Request, Response) -> Unit
t
thanks, that helps
k
You're welcome
t
maybe the best approach here would be to keep the functional interfaces as java, since i intend to use this with both java and kotlin? or is there a better approach?
k
Yes. You can do that. Using Kotlin's functional type results in
FunctionN
interfaces in Java which might not be as pretty as a specialized interface like your
Handler
Well. Except you intend for a 100% KT src, in which case, you'll eventually end up converting everything anway