title: Why can I access the attribute of a specific struct when it's stored in a collection of abstract types?
body: <pre><code>abstract type Elf end 
  
  struct LightElf &lt;: Elf
      name::String 
      life::Int32
  end 
  
  struct DarkElf &lt;: Elf
      name::String
      life::Int32
      # This attribute is only in DarkElf.
      enchantment::Int32
  end
  
  amber = LightElf(&quot;Amber&quot;,100)
  charles = DarkElf(&quot;Charles&quot;,20,45)
  
  elves = Elf[]
  push!(elves,amber,charles)
  charles = DarkElf(&quot;Charles&quot;,20,45)
  println(elves[2].enchantment)
  
  &gt; 45
  </code></pre>
  <p>Why can I access the <code>enchantment</code> field from <code>charles</code> when it's being stored in an array of abstract <code>Elf</code> objects?</p>
  <p>In a language like <code>C#</code> or <code>Java</code>, a parent would not know about any attributes specific to that sub class. Obviously, we don't have <code>abstract</code> classes, so we don't know what attributes will make a generic <code>Elf</code>. I guess you could ask, how does Julia know about the attributes that are in a <code>struct</code>?</p>