To understand why this is not possible, it is useful to think about what an interface variable actually is. An interface value takes two words, the first of which describes the type of value contained, and the second either (a) contains the contained value (if it is placed inside the word), or (b) a pointer to the storage for the value (if the value does not fit inside the word).
It is important to note that (1) the contained value belongs to the interface variable, and (2) the memory for this value can be reused when a new value is assigned to the variable. Knowing this, consider the following code:
var v interface{} v = int(42) p := GetPointerToInterfaceValue(&v)
Now, storage for the whole has been reused to hold the pointer, and *p now an integer representation of that pointer. You can see how this can destroy the type system, so Go does not provide a way to do this (outside of using the unsafe package).
If you need a pointer to the structures that you store in the list, then one option would be to save pointers to the structures in the list, and not to the struct values ββdirectly. Alternatively, you can pass *list.Element values ββas references to the structures they contain.
source share