Hello,
I defined my own little extension function List.findIfNone:
fun <E> List<E>.findIfNone(searchBlock: (E) -> Boolean, ifNoneElement: E): E {
val element = find { searchBlock(it) }
if(element != null) {
return element
}
return ifNoneElement
}
Now I call it this way supplying null to the 2nd method parameter:
fun main(args: Array<String>) {
val list = listOf("abc", "def", "ghi", "jkl", "mno")
val foundElement = list.findIfNone({it == "ghi"}, null)
println(foundElement)
}
I don’t understand why I can put in null there although
ifNoneElement: E
is defined and not
ifNoneElement: E?
Am using Kotlin 1.3.11.