Extension Function For Kotlin Data Class
I have a data class which looks something like this data class SuggestionResponse( val metadata: Metadata, val response: Response ) data class Response( ///blah blah ) data
Solution 1:
Just create an extension function on SuggestionResponse
class and you'll have access to the properties of SuggestionResponse
class:
fun SuggestionResponse.hello() {
//`metadata` property is available here//`response` property is available hereval time = metadata.timeleft
}
And then you'll be able to call it on an instance of SuggestionResponse
class:
suggestionResponse.hello()
More info about extension functions.
Post a Comment for "Extension Function For Kotlin Data Class"