【发布时间】:2020-09-15 22:37:07
【问题描述】:
我不知道如何正确地将 ProductEntity(一种 ProductEntity)的子级转换为 Product。
class ProductEntity(id: EntityID<Int>) : BaseIntEntity(id, Products) {
companion object : BaseIntEntityClass<ProductEntity>(Products)
var name by Products.name
var parentProduct by ProductEntity optionalReferencedOn Products.parentProduct
fun toPojo() = Product(idValue, name, parentProduct?.toPojo())
}
data class Product(
val id: Int,
val name: String,
val parentProduct: Product?
)
此时出现错误:类型检查遇到递归问题。 能告诉我怎么解决吗?
【问题讨论】:
-
请在
toPojo函数中添加显式类型:fun toPojo() : Product = Product(idValue, name, parentProduct?.toPojo())
标签: kotlin ktor kotlin-exposed