Parsing xml kotlin android

前端 未结 2 603
余生分开走
余生分开走 2021-01-19 07:17

I have xml like this:




Сегодня вас могут здорово огорчить. Если от расстройства все начнет валится из рук, просто спо         


        
2条回答
  •  面向向阳花
    2021-01-19 07:47

    The answer of @daementus is almost perfect. If you want to use constructor injection with default parameters, you have to force Kotlin to generate constructor overloads:

    data class Section @JvmOverloads constructor(
    
        @field:Element(name = "id")
        @param:Element(name = "id")
        val id: Long,
    
        @field:Attribute(name = "title", required = false)
        @param:Attribute(name = "title", required = false)
        val title: String = ""
    )
    

    Without it you will get Constructor not matched for class Section. By default Kotlin generates a constructor with all parameters and a special constructor.

    Note: I would prefer to answer in the comments but I don't have enough points.

提交回复
热议问题