Issue
I'm trying to do something similar to :
val telephonyCallback = object: TelephonyCallback() implements TelephonyCallback.ServiceStateListener {
override fun onServiceStateChanged(serviceState: ServiceState) {
}
}
Is it possible with Kotlin?
Solution
You can provide multiple supertypes separated by commas:
val telephonyCallback = object: TelephonyCallback(), TelephonyCallback.ServiceStateListener {}
Just note it does not work as you may expect. Object expressions create anonymous classes and that means there is no explicit class that extends/implements both supertypes. In some cases you can use telephonyCallback
as both supertypes (for example if it's a local variable), in other cases you can only keep one of its supertypes and you have to choose it explicitly (property, function parameter).
If you want to be able to pass such telephonyCallback
variable anywhere, you have to create a regular class for it, so it can be referenced in the code.
Answered By - broot
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.