Concerning function types in Kotlin
The following gives exception kotlin.UninitializedPropertyAccessException: lateinit property foo has not been initialized
class SomeClass (){
lateinit var foo: (String) -> Int
}
val result : Int = c.foo("hello")
println("result $result")
The following 2 do not even compile
class SomeClass (){
lateinit var foo: (String) -> Int = 1
}
class SomeClass (){
var foo: (String) -> Int = 1
}
How do I provide an implementation for foo?
You can declare
foofunction as val in this wayand use it like
foo.invoke("")or if you need to uselateinit varyou should initialize it later in class