I’m playing around with the Ninja Web Framework (converting the example to Kotlin) and I’ve hit upon this annoyingly basic problem: converting a string to a Long.
fun asyncEcho(ctx: Context) : Result? {
executorService.schedule(object: Runnable {
override fun run() {
ctx.returnResultAsync(Results.json()?.render(ctx.getParameter(“message”)))
}
}, <strong>ctx.getParameter("timeout")</strong>, TimeUnit.MILLISECONDS) <strong>// <-- The ctx.getParameter call returns a string; I need it as as a long</strong>
return Results.async()
also you could call executorService.schedule function with a SAM construct
``
fun asyncEcho(ctx: Context) : Result? {
executorService.schedule({
ctx.returnResultAsync(Results.json()?.render(ctx.getParameter(“message”))) }, ctx.getParameter(“timeout”)!!.toLong() /*As Andrey suggest */, TimeUnit.MILLISECONDS) // <– The ctx.getParameter call returns a string; I need it as as a long return Results.async() }
fun asyncEcho(ctx: Context) : Result? {
executorService.schedule(object: Runnable {
override fun run() {
ctx.returnResultAsync(Results.json()?.render(ctx.getParameter("message")))
}
}, ctx.getParameter("timeout")?.toLong(), TimeUnit.MILLISECONDS) //<-- Using toLong()
return Results.async()
}
And I got this:
Kotlin: None of the following functions can be called with the arguments supplied:
public abstract fun schedule(p0: java.lang.Runnable, p1: jet.Long, p2: java.util.concurrent.TimeUnit): java.util.concurrent.ScheduledFuture<out jet.Any?> defined in java.util.concurrent.ScheduledExecutorService
public abstract fun <V> schedule(p0: java.util.concurrent.Callable<V>, p1: jet.Long, p2: java.util.concurrent.TimeUnit): java.util.concurrent.ScheduledFuture<V> defined in java.util.concurrent.ScheduledExecutorService
There's something about going between Java and Kotlin I'm not quite getting ... :|