I have following in my kotlin code:
return Failsafe.with<Boolean>(retryPolicy)
// Here I want fall back to false
.withFallback { -> false} // Does not work
.get { ->
publish(event)
true
}
Kotlin compiler complains that:
Error:(89, 14) Kotlin: Overload resolution ambiguity:
public final fun withFallback(p0: (() -> Boolean!)!): SyncFailsafe! defined in net.jodah.failsafe.SyncFailsafe
public final fun withFallback(p0: (() -> Unit)!): SyncFailsafe! defined in net.jodah.failsafe.SyncFailsafe
But this way it works:
val fallback: () -> Boolean = { false }
return Failsafe.with<Boolean>(retryPolicy)
// Here I want fall back to false
.withFallback(fallback) // Works
.get { ->
publish(event)
true
}
Could somebody explain me why it does not work with lambda literal outside brackets? And how to make it work with lambda inline?
->
, they are only necessary when you are defining parameters in front of it – msrd0