# Why doesn't convert(Symbol, "foo") work?

**URL:** <https://discourse.julialang.org/t/why-doesnt-convert-symbol-foo-work/54357>\
**Category:** General Usage\
**Created:** [February 1, 2021, 3:54am UTC](https://discourse.julialang.org/t/why-doesnt-convert-symbol-foo-work/54357 "2021-02-01T03:54:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jzr](https://avatars.discourse-cdn.com/v4/letter/j/eb9ed0/32.png) [@jzr](https://discourse.julialang.org/u/jzr)\
**Post date:** [February 1, 2021, 3:54am UTC](https://discourse.julialang.org/t/why-doesnt-convert-symbol-foo-work/54357/1 "2021-02-01T03:54:15Z")

</div>

Since the `Symbol` constructor works, is there a reason why `convert(Symbol, "foo")` shouldn’t work?

```julia
julia> Symbol("foo")
:foo

julia> convert(Symbol, "foo")
ERROR: MethodError: Cannot `convert` an object of type String to an object of type Symbol

```

---

<div class="post-metadata">

**Author:** ![cstjean](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cstjean/32/1444_2.png) [@cstjean](https://discourse.julialang.org/u/cstjean)\
**Post date:** [February 1, 2021, 5:56am UTC](https://discourse.julialang.org/t/why-doesnt-convert-symbol-foo-work/54357/2 "2021-02-01T05:56:42Z")

</div>

`convert` happens automatically inside of the standard constructor.

```julia
julia> struct Foo
           a::Symbol
       end

julia> Foo("lion")
ERROR: MethodError: Cannot `convert` an object of type String to an object of type Symbol
Closest candidates are:
  convert(::Type{T}, ::T) where T at essentials.jl:171
  Symbol(::String) at boot.jl:436
  Symbol(::AbstractString) at strings/basic.jl:226
  ...
Stacktrace:
 [1] Foo(::String) at ./REPL[1]:2
 [2] top-level scope at REPL[2]:1

```

would work if `convert` was defined. Presumably, the Julia developers judged that conversion to/from strings should be done explicitly instead. I’m sure other language designers would have chosen otherwise, but personally I agree with the choice…

See also [https://github.com/JuliaLang/julia/issues/39001](https://github.com/JuliaLang/julia/issues/39001)
