mardi 9 août 2016

How to take address of argument with reflection

Basic situation:

you can do this in golang:

func addrOf(foo interface{}) interface{} {
    return &foo
}

but you cannot do this:

func addrOf(foo interface{}) interface{} {
    fooValue := reflect.ValueOf(foo)
    return fooValue.Addr().Interface()
}

Am I doing something wrong? why is foo addressable to the language but not to reflect?





Aucun commentaire:

Enregistrer un commentaire