# Is 'name' not allowed in enums?

**URL:** <https://discuss.kotlinlang.org/t/is-name-not-allowed-in-enums/24191>\
**Category:** Support\
**Created:** [February 15, 2022, 12:43pm UTC](https://discuss.kotlinlang.org/t/is-name-not-allowed-in-enums/24191 "2022-02-15T12:43:53Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![beepsoft](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/beepsoft/32/8145_2.png) [@beepsoft](https://discuss.kotlinlang.org/u/beepsoft)\
**Post date:** [February 15, 2022, 12:43pm UTC](https://discuss.kotlinlang.org/t/is-name-not-allowed-in-enums/24191/1 "2022-02-15T12:43:53Z")

</div>

Hi,

I have an enum class which has an enum value called `name`

```kotlin

enum class ColumnNames {
    id,
    name,
}

fun main() {
    println(ColumnNames.name)
}

```

and it fails to compile with

```auto
Conflicting declarations: enum entry name, public final val name: String

```

Is there a way to have an enum value called “name”? I tried putting it between backticks, but it didn’t work.

Here’s this example in playground:  
[https://play.kotlinlang.org/#eyJ2ZXJzaW9uIjoiMS42LjEwIiwicGxhdGZvcm0iOiJqYXZhIiwiYXJncyI6IiIsIm5vbmVNYXJrZXJzIjp0cnVlLCJ0aGVtZSI6ImlkZWEiLCJjb2RlIjoiXG5lbnVtIGNsYXNzIENvbHVtbk5hbWVzIHtcbiAgICBpZCxcbiAgICBuYW1lLFxufVxuXG5mdW4gbWFpbigpIHtcbiAgICBwcmludGxuKENvbHVtbk5hbWVzLm5hbWUpXG59In0=](https://play.kotlinlang.org/#eyJ2ZXJzaW9uIjoiMS42LjEwIiwicGxhdGZvcm0iOiJqYXZhIiwiYXJncyI6IiIsIm5vbmVNYXJrZXJzIjp0cnVlLCJ0aGVtZSI6ImlkZWEiLCJjb2RlIjoiXG5lbnVtIGNsYXNzIENvbHVtbk5hbWVzIHtcbiAgICBpZCxcbiAgICBuYW1lLFxufVxuXG5mdW4gbWFpbigpIHtcbiAgICBwcmludGxuKENvbHVtbk5hbWVzLm5hbWUpXG59In0=)

---

<div class="post-metadata">

**Author:** ![al3c](https://avatars.discourse-cdn.com/v4/letter/a/e47774/32.png) [@al3c](https://discuss.kotlinlang.org/u/al3c)\
**Post date:** [February 15, 2022, 12:47pm UTC](https://discuss.kotlinlang.org/t/is-name-not-allowed-in-enums/24191/2 "2022-02-15T12:47:54Z")

</div>

That’s not possible. Note that convetions suggest either `Name` or `NAME`.

> **[Coding conventions | Kotlin](https://kotlinlang.org/docs/coding-conventions.html#property-names)**

---

<div class="post-metadata">

**Author:** ![beepsoft](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/beepsoft/32/8145_2.png) [@beepsoft](https://discuss.kotlinlang.org/u/beepsoft)\
**Post date:** [February 15, 2022, 12:56pm UTC](https://discuss.kotlinlang.org/t/is-name-not-allowed-in-enums/24191/3 "2022-02-15T12:56:08Z")

</div>

@al3c thanks for the quick answer! Yes, I know that it should be NAME, however this is from a generated code (a client generated from a graphql schema) and it uses the names found in the schema.

Can you point me to where is this defined that “name” cannot be an enum member?

---

<div class="post-metadata">

**Author:** ![al3c](https://avatars.discourse-cdn.com/v4/letter/a/e47774/32.png) [@al3c](https://discuss.kotlinlang.org/u/al3c)\
**Post date:** [February 15, 2022, 1:08pm UTC](https://discuss.kotlinlang.org/t/is-name-not-allowed-in-enums/24191/4 "2022-02-15T13:08:50Z")

</div>

It’s not specifically forbidden, but all enums inherit from java.lang.Enum  
[https://docs.oracle.com/javase/7/docs/api/java/lang/Enum.html](https://docs.oracle.com/javase/7/docs/api/java/lang/Enum.html)

and that has already a `name` property.

---

<div class="post-metadata">

**Author:** ![beepsoft](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/beepsoft/32/8145_2.png) [@beepsoft](https://discuss.kotlinlang.org/u/beepsoft)\
**Post date:** [February 15, 2022, 1:11pm UTC](https://discuss.kotlinlang.org/t/is-name-not-allowed-in-enums/24191/5 "2022-02-15T13:11:33Z")

</div>

Yes, of course, I didn’t think of Java Enum, it makes sense! Thanks again!

---

<div class="post-metadata">

**Author:** ![Alexey.Belkov](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/alexey.belkov/32/5215_2.png) [@Alexey.Belkov](https://discuss.kotlinlang.org/u/Alexey.Belkov)\
**Post date:** [February 15, 2022, 2:02pm UTC](https://discuss.kotlinlang.org/t/is-name-not-allowed-in-enums/24191/6 "2022-02-15T14:02:22Z")

</div>

Please vote for [https://youtrack.jetbrains.com/issue/KT-44885](https://youtrack.jetbrains.com/issue/KT-44885)

---

<div class="post-metadata">

**Author:** ![beepsoft](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/beepsoft/32/8145_2.png) [@beepsoft](https://discuss.kotlinlang.org/u/beepsoft)\
**Post date:** [February 15, 2022, 2:17pm UTC](https://discuss.kotlinlang.org/t/is-name-not-allowed-in-enums/24191/7 "2022-02-15T14:17:18Z")

</div>

Thanks, I just did!

---

<div class="post-metadata">

**Author:** ![clovisai](https://avatars.discourse-cdn.com/v4/letter/c/a9adbd/32.png) [@clovisai](https://discuss.kotlinlang.org/u/clovisai)\
**Post date:** [February 22, 2022, 1:53pm UTC](https://discuss.kotlinlang.org/t/is-name-not-allowed-in-enums/24191/8 "2022-02-22T13:53:31Z")

</div>

That is both true and false. The name property is inspired from Java, but it’s not about inheritance. You also can’t use `name` in Kotlin/JS, where nothing inherits from Java.

---

<div class="post-metadata">

**Author:** ![akurczak](https://avatars.discourse-cdn.com/v4/letter/a/f07891/32.png) [@akurczak](https://discuss.kotlinlang.org/u/akurczak)\
**Post date:** [February 22, 2022, 2:26pm UTC](https://discuss.kotlinlang.org/t/is-name-not-allowed-in-enums/24191/9 "2022-02-22T14:26:59Z")

</div>

It actually is about inheritance, but of `kotlin.Enum`, see [language specification](https://kotlinlang.org/spec/built-in-types-and-their-semantics.html#kotlin.enum):

> `kotlin.Enum<T>` is the built-in parameterized classifier type which is used as a superclass for all [enum classes](https://kotlinlang.org/spec/declarations.html#enum-class-declaration): every enum class `E` is implicitly a subtype of `kotlin.Enum<E>` .

On JVM they happen to be the same:

```run-kotlin
fun main() {
    println(java.lang.Enum::class == kotlin.Enum::class)
}

```
