【问题标题】:Moshi custom qualifier annotation in KotlinKotlin 中的 Moshi 自定义限定符注释
【发布时间】:2016-03-26 18:50:42
【问题描述】:

我在将某些代码转换为 kotlin 时遇到问题。自定义限定符的注释被忽略。 我这样定义它们:

class ColorAdapter {

    @ToJson
    internal fun toJson(@PassDefinitions.HexColor rgb: Int): String {
        return String.format("#%06x", rgb)
    }

    @FromJson
    @PassDefinitions.HexColor
    internal fun fromJson(rgb: String): Int {
        return Color.parseColor(rgb)
    }
}

并尝试像这样使用它们:

@HexColor
override var backgroundColor: Int = 0

但它只是被忽略了。

【问题讨论】:

    标签: kotlin moshi


    【解决方案1】:

    请试试这个语法:

    @field:[HexColor]
    override var backgroundColor: Int = 0
    

    【讨论】:

      猜你喜欢
      • 2019-02-14
      • 1970-01-01
      • 2017-03-09
      • 2017-03-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多