lundi 4 avril 2016

Why does golang allow pointers to interfaces?

In my tenure of writing Go code, I have never encountered a case, nor can I think of one that would require using a pointer to an interface, except for perhaps writing a library that makes heavy use of runtime reflection. Some people allude to the fact that there are valid reasons for doing so, but seem to never elaborate further. This feature also seems to cause quite a bit of confusion with developers who are getting started with Go.

main.go:22: cannot use &a (type *A) as type **interface {} in argument to run

What would be a good example of using an interface pointer? Also, given the limited use case, why is this functionality so explicitly available in the language and not reserved to some library like reflect?





Aucun commentaire:

Enregistrer un commentaire