Is there a way in kotlin to prevent function call if all (or some) arguments are null? For example Having function:
fun test(a: Int, b: Int) { /* function body here */ }
I would like to prevent null checks in case when arguments are null
. For example, for arguments:
val a: Int? = null
val b: Int? = null
I would like to replace:
a?.let { b?.let { test(a, b) } }
with:
test(a, b)
I imagine that function definition syntax could look something like this:
fun test(@PreventNullCall a: Int, @PreventNullCall b: Int)
And that would be equivalent to:
fun test(a: Int?, b: Int?) {
if(a == null) {
return
}
if(b == null) {
return
}
// function body here
}
Is something like that (or similar) possible to reduce caller (and possibly function author) redundant code?