I was recently playing with the Go language and I bumped into something a bit weird to say the least, let's consider a very simple function:
func main() {
n, e := fmt.Println(`He said: "Hello"`)
fmt.Printf("%T
", n)
}
Which outputs what I was expecting:
He said: "Hello"
int
Now if I want to display the type of e
:
func main() {
n, e := fmt.Println(`He said: "Hello"`)
fmt.Printf("%T
", e)
}
and this time prints out:
He said: "Hello"
<nil>
I get the part that there is no error so e
is an empty pointer: nil
but I would have not expected to be a ~~type~~ on its own.
Why am I not getting the actual type?
If so, is there a workaround? (not saying my use case is a realistic one but curious if there is any possibility)