The only solution I know is using fmt.Sprint
or similar functions. I already look into builtin
package but it has only error
interface, string
is just a normal type, not interface.
As @volker mentioned; you cannot as the empty interface has no methods.
Please note: fmt.Sprint
, fmt.Sprintf
etc. does call Stringer interface first if its exists. It is elegant way.
Example of calling stringer interface after type assertion.
var a SomeType
if v, ok := a.(fmt.Stringer); ok {
fmt.Println(v.String())
}