Can I declare an enum class that has the same name...
# announcements
g
Can I declare an enum class that has the same name as one of its members in Kotlin. Example:
Copy code
enum class Potato(val a : Int) {
     Potato(3);
}
This is possible in Java but it seems like it's not allowed in Kotlin?
p
Looks like a bug
d
edit: It was missing
val
, I found that it is unrelated to the question
p
Report it and use the default naming convention of enums :
POTATO
g
I wish I could change it to match convention but I have to keep an API already in place and I was just trying to translate this enum to Kotlin
s
The error message states that it's not allowed, though?
Use of enum entry names as types is not allowed
Why it's not allowed I can't say for sure.
g
It only seems to be a problem with the constructor parameter.
Copy code
enum class Potato{
     Potato;
}
this is allowed
p
The message is wrong
It's meant for sth like this I assume
Copy code
enum class Vegetable { POTATO }
fun sth(t: Vegetable.POTATO) {}
File a bug 🙂
g
where do I file the bug @Paul Woitaschek?
p