I'd like to be able to do the below (minimal example, not real use-case):
data class Customer(
name: String,
address: object {
street: String,
city: String
}
)
Is this currently possible via some syntax?
I'd like to be able to do the below (minimal example, not real use-case):
data class Customer(
name: String,
address: object {
street: String,
city: String
}
)
Is this currently possible via some syntax?
Share Improve this question asked Mar 7 at 6:44 RollieRollie 4,7794 gold badges39 silver badges68 bronze badges 4 |2 Answers
Reset to default 1Seems like the current answer is unfortunately "you can't". Maybe in the future...
You can achieve that by using by creating two different classes Customer
and Address
data class Customer(
var name: String,
var address: Address
)
data class Address(
var street: String,
var city: String
)
and if you want use different classes instead of Address
than you can use Any
which can hold any type of object
data class Customer(
var name: String,
var address: Any
)
var address = object : Any() { var street: String }
. Not sure how you could use it though. Can you provide a use case? – k314159 Commented Mar 7 at 15:00