when i try to call a function on an object i get the error that the function does not exist, allthough it exists. i have following class
class WrapperDto (dto : AbstractDto){
val type = dto::class.simpleName
val dto = dto
fun isTypeOf(dto: KClass<InitDto>) : Boolean {
return type == dto::class.simpleName
}
}
and try to call the method isTypeOf like this later
client.onmessage = fun(wrapperDto: WrapperDto){
try{
println("trying to get the type type of the dto generated by a json string")
val typeOf = wrapperDto.isTypeOf(InitDto::class)
println("success")
} catch (e : Exception){
writeMessage("error")
}
}
but get following error:
trying to get the type of the dto generated by a json string
main$lambda (anonymous function) Uncaught TypeError: wrapperDto.isTypeOf_d8ukon$ is not a function
in intellij the code is not marked as error, and the function exists, so why do i get this error
@Richard could you please provide a self-contained example?
I can’t reproduce it with
import kotlin.reflect.KClass
class WrapperDto (dto : AbstractDto){
val type = dto::class.simpleName
val dto = dto
fun isTypeOf(dto: KClass<InitDto>) : Boolean {
return type == dto::class.simpleName
}
}
open class AbstractDto
class InitDto : AbstractDto()
fun main(args: Array<String>) {
val wrapperDto = WrapperDto(InitDto())
try{
println("trying to get the type type of the dto generated by a json string")
val typeOf = wrapperDto.isTypeOf(InitDto::class)
println("success")
} catch (e : Exception){
println("error")
}
}