How can we use the actual type pointed to by an empty interface to create a new instance of that type in Go?
<p>Please check the below program. Var <code>z</code> is of type <code>interface{}</code>. It stores the type of struct <code>X</code>. But I cannot use it to create a new instance of <code>X</code>. I have some requirement where I need to keep the type of the object in an <code>interface{}</code> variable, and use that to create an instance of that type. Here is a <a href="https://play.golang.org/p/RnUwShrz54" rel="nofollow">link for the snippet on go playground</a></p>

<pre><code>package main

import (
    "fmt"
    "reflect"
)

type X struct {
    a int
    b int
}

type MyInt int

func main() {
    x := X{}
    y := reflect.TypeOf(x)
    fmt.Printf("%v\n", reflect.New(y))

    var z interface{}
    z = y
    fmt.Printf("%v\n", z) // prints main.X

    //Below line throws the error
    fmt.Printf("%v\n", reflect.New(z)) //----&gt; This line throws error

}
</code></pre>