mercredi 3 juin 2015

Create new object knowing reflected type

In function, one of arguments I'm passing

reflect.TypeOf(Person)

where person is struct with few strings. If another function which accepts this argument, I want to instantiate this empty struct knowing its reflected type.

I have tried following

ins := reflect.New(typ)  //typ is name or passed reflect.TypeOf(Person)

But this returns me nil. What am I doing wrong?





Aucun commentaire:

Enregistrer un commentaire