# How can I determine the name of an enum value?

**URL:** <https://discourse.julialang.org/t/how-can-i-determine-the-name-of-an-enum-value/82394>\
**Category:** General Usage\
**Tags:** question, enum\
**Created:** [June 7, 2022, 11:20pm UTC](https://discourse.julialang.org/t/how-can-i-determine-the-name-of-an-enum-value/82394 "2022-06-07T23:20:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [June 7, 2022, 11:20pm UTC](https://discourse.julialang.org/t/how-can-i-determine-the-name-of-an-enum-value/82394/1 "2022-06-07T23:20:03Z")

</div>

How can I get the name of an enum value?

```julia
@enum Animal dog cat
Int(cat) # works
String(cat) # not working

```

How can I get the string representation of a variable of type Animal?  
I want to get the string “cat” or “dog”.

---

<div class="post-metadata">

**Author:** ![Mason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mason/32/2423_2.png) [@Mason](https://discourse.julialang.org/u/Mason)\
**Post date:** [June 7, 2022, 11:24pm UTC](https://discourse.julialang.org/t/how-can-i-determine-the-name-of-an-enum-value/82394/2 "2022-06-07T23:24:12Z")

</div>

You need to use `Symbol` to get the name. That can then be converted to a string though

```julia
julia> @enum Animal dog cat

julia> Symbol(cat)
:cat

julia> String(Symbol(cat))
"cat"

```

---

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [June 7, 2022, 11:33pm UTC](https://discourse.julialang.org/t/how-can-i-determine-the-name-of-an-enum-value/82394/3 "2022-06-07T23:33:29Z")

</div>

Thanks a lot!

Any idea why the direct conversion is not implemented?

---

<div class="post-metadata">

**Author:** ![JeffreySarnoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeffreysarnoff/32/1980_2.png) [@JeffreySarnoff](https://discourse.julialang.org/u/JeffreySarnoff)\
**Post date:** [June 9, 2022, 1:55am UTC](https://discourse.julialang.org/t/how-can-i-determine-the-name-of-an-enum-value/82394/4 "2022-06-09T01:55:53Z")

</div>

The function `string(x)` appeared in Julia long before the type `String`.  
The type `String` appeared in advance of the deep move from types with constructors to types as constructors. And `string` was present to be the “constructor method” that delivers `T<:AbstractString`.

`strx = string(x)` does “construct” `strx` from `x`, and  
expect `isa(strx, AbstractString)`.

```julia
using Test

a, stra = 1, "1"

@test string(a) == stra
@test_throws MethodError String(a)

```
