title: How can I set the value of a struct variable on an interface slice?
body: <p>How can I set <code>testEntity.Val</code> that is contained in <code>[]interface{}{}</code> using reflection?</p>
  
  <pre><code>type testEntity struct {
      Val int
  }
  
  func main() {
  
      slice := []interface{}{testEntity{Val: 3}}
      sliceValue := reflect.ValueOf(slice)
      elemValue := sliceValue.Index(0)
  
      // Prints: can set false
      fmt.Println("can set", elemValue.Elem().Field(0).CanSet())
  
  }
  </code></pre>
  
  <p><a href="http://play.golang.org/p/lxtmu9ydda" rel="noreferrer">http://play.golang.org/p/lxtmu9ydda</a></p>
  
  <p>Can someone explain why it works with <code>[]testEntity{}</code> but not <code>[]interface{}{}</code> as shown here: <a href="http://play.golang.org/p/HW5tXEUTlP" rel="noreferrer">http://play.golang.org/p/HW5tXEUTlP</a></p>