https://kotlinlang.org logo
k

kevin.cianfarini

02/20/2020, 3:09 PM
I'm trying to do some constructor delegation and I'm getting the error
There's a cycle in the delegation calls chain
and I'm not quite sure why. Does anyone know how to fix this?
Copy code
internal class EmptyComponentModel private constructor(
    override val countryCode: CountryCode,
    override val saleStatus: SaleStatus,
    override val price: Monetary? = null,
    override val saleNotes: String? = null
) : PlacardComponentModel(ListingSaleType.Unknown) {

    constructor(countryCode: CountryCode, saleStatus: SaleStatus) : this(
        countryCode = countryCode,
        saleStatus = saleStatus
    )
}
There doesn't seem to be a lot of information about this online that I can find
s

streetsofboston

02/20/2020, 3:11 PM
What if you try this:
Copy code
internal class EmptyComponentModel private constructor(
    override val countryCode: CountryCode,
    override val saleStatus: SaleStatus,
    override val price: Monetary? = null,
    override val saleNotes: String? = null
) : PlacardComponentModel(ListingSaleType.Unknown) {

    constructor(countryCode: CountryCode, saleStatus: SaleStatus) : this(
        countryCode = countryCode,
        saleStatus = saleStatus,
        price = null,
        saleNotes = null
    )
}
k

kevin.cianfarini

02/20/2020, 3:11 PM
adding the remaining properties fixes this
Copy code
constructor(countryCode: CountryCode, saleStatus: SaleStatus) : this(
        countryCode = countryCode,
        saleStatus = saleStatus,
        price = null,
        saleNotes = null
    )
Is this a compiler/IDE bug?
s

streetsofboston

02/20/2020, 3:12 PM
You were calling the secondary constructor recursively
k

kevin.cianfarini

02/20/2020, 3:12 PM
🤦‍♂️ duh
thanks
s

streetsofboston

02/20/2020, 3:12 PM
🙂 We’ve all been there 🙂
k

kevin.cianfarini

02/20/2020, 3:13 PM
the imposter syndrome is strong this morning!! lol
8 Views