Hello group,
1. If the operand is a reflect.Value, the operand is replaced by the concrete value that it holds, and printing continues with the next rule.
5. If an operand implements method String() string, that method will be invoked to convert the object to a string, which will then be formatted as required by the verb (if any).
package main
import (
"fmt"
"reflect"
)
type SpecialInt int
func (i SpecialInt) String() string { return fmt.Sprintf("SpecialInt(%d)", int(i)) }
func main() {
v := reflect.ValueOf(SpecialInt(73))
fmt.Printf("%+v\n", v)
fmt.Printf("%+v\n", v.Interface())
}
I expect the first fmt.Printf call to substitute the concrete value of v, which is SpecialInt(73), invoke the String() method on it, and print "SpecialInt(73)". However, it just prints "73". On the contrary, the second fmt.Printf call (correctly) prints "SpecialInt(73)".
Is there anything I'm missing here, or maybe something wrong with the Go documentation or implementation?
Thanks.