Is there a more succinct of casting a literal into an empty interface? A lot of the relevant community issues are about coercing an interface to a literal but not vice versa.
Looking for something of the form:
func pointerInterfaceOf(in interface{}) *interface{} {
return &in
}
I have tried
&reflect.ValueOf(in).Interface() // Compiler error
But that is a compiler error.
If you want to cast something to interface{}
, just use the normal casting syntax:
interface{}(whatever)
If the reflect value is a *interface{}
, then use:
return reflect.Value(in).Interface().(*interface{})
If the reflect value is not an pointer to an interface, then the shortest code is:
x := reflect.ValueOf(in).Interface()
return &x
The application cannot use &reflect.ValueOf(in).Interface()
because the return value from a function is not addressable.