Conflicting 'name' declaration in enum

后端 未结 1 425
太阳男子
太阳男子 2021-01-14 06:50

I have a simple enum class in which I would like to have a field called name.

enum class DeviceFieldQuery(val clazz: Class<*>) {
             


        
相关标签:
1条回答
  • 2021-01-14 06:56

    Enums in Kotlin already have a name property already defined (like Java). This is conflicting with your enum called name. To fix it, you could capitalize it, which is more idiomatic:

    enum class DeviceFieldQuery(val clazz: Class<*>) {
        Id(Int::class.java),
        Name(String::class.java),
    }
    
    0 讨论(0)
提交回复
热议问题