Your pointer String method is not being called. That is expected behavior, pointer methods cannot be called on values for the reasons you gave.
{old 12}
is the default output for a struct. See fmt Printing...
struct: {field0 field1 ...}
Perhaps confusingly, fmt.Println(u1.String())
will work. This is because Go has quietly changed that to fmt.Println(&u1.String())
for your convenience. From Effective Go: Methods, Pointers vs. Values...
There is a handy exception, though. When the value is addressable, the language takes care of the common case of invoking a pointer method on a value by inserting the address operator automatically.