admin管理员组文章数量:1410674
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
)
本文标签: kotlinIs there a way to have structured data in data classes with anonymous classesStack Overflow
版权声明:本文标题:kotlin - Is there a way to have structured data in data classes with anonymous classes? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744944708a2633704.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
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