how do i write in Kotlin like java?
Callback callback= new Callback()
{
@Override
public void getCallback(ServerResponse serverResponse) {
}
}
how do i write in Kotlin like java?
Callback callback= new Callback()
{
@Override
public void getCallback(ServerResponse serverResponse) {
}
}
You can use following code in Kotlin.
var callback:Callback = object:Callback() {
fun getCallback(serverResponse:ServerResponse) {
}
}
You can use this link to convert your Java code to kotlin. https://try.kotlinlang.org
var callback:Callback = object:Callback() {
override fun getCallback(serverResponse:ServerResponse) {
}
}
var callback:Callback
says that the variable type is a Callback
object:Callback() { }
is an anonymous class. It has no name when created, before being assigned to var callback
. It's similar to the new Callback()
code.
override
replaces @Override
fun
indicates that it is a function
Callback
interface. Actually the overridden function getCallback
has a name, 'getCallback', which is not anonymous. –
Bwana You can use following code in Kotlin.
var callback:Callback = object:Callback() {
fun getCallback(serverResponse:ServerResponse) {
}
}
You can use this link to convert your Java code to kotlin. https://try.kotlinlang.org
© 2022 - 2024 — McMap. All rights reserved.