title: (Julia 1.x) Getting type of #undef variable
body: <p>I am looking to get the types of the fields within a <code>struct</code> in order to set the field values correspondingly. Some data types initialise values on instantiation (e.g. <code>Int64</code>, <code>Float64</code>), whereas other types initialise to <code>#undef</code> (e.g. <code>String</code>, <code>Array</code>). Whilst <code>typeof(getfield())</code> works for the former types, it throws <code>UndefRefError</code> for the latter:</p>
  
  <pre><code>julia&gt; mutable struct MyStruct
             a::Int64
             b::String
             MyStruct() = new()
         end
  
  julia&gt; foo = MyStruct()
  MyStruct(0, #undef)
  
  julia&gt; typeof(getfield(foo, :a))
  Int64
  
  julia&gt; typeof(getfield(foo, :b))
  ERROR: UndefRefError: access to undefined reference
  Stacktrace:
   [1] top-level scope at none:0
  </code></pre>
  
  <p>Is there is way to get the type of an uninitialised variable or does <code>#undef</code> indicate the distinct lack of a type? Alternatively, is it possible to initialise default values using the inner constructor? e.g.</p>
  
  <pre><code>julia&gt; mutable struct MyStruct
             a::Int64
             b::String
             MyStruct() = new(b = "")
         end
  </code></pre>