https://kotlinlang.org logo
k

Krish

04/27/2020, 5:10 PM
Hey guys, is it possible to extend a data class with an abstract class? My use case is as follows, I have a CommonResponse Params abstract class
Copy code
abstract class CommonResponseParams (
    val type: String,
    val code: String,
    val message: String,
    @SerializedName("request_id")
    val requestId: String,
    val detail: CommonDetailsResponseObject?
)
And I have a more specific Response Params which has the Common Params on top of it I wish to extend this data class with the abstract class above
Copy code
data class GetCategoryAttributeResponse (
    val commonDetails : CommonDetailsResponseObject,
    @SerializedName("data")
    val getCategoryData: CategoryAttributeResponseData
)
d

David Eriksson

04/28/2020, 5:31 AM
No, it is not possible. A data class can implement interfaces though.
2 Views