I was making a simple linked list interface to find out about Go interfaces when I came across this apparent inconsistency. nextTalways zero, but the return value is next()not equal.
package main
import (
"fmt"
)
type LinkedList interface {
next() LinkedList
}
type T struct {
nextT *T
}
func (t *T) next() LinkedList {
return t.nextT
}
func main() {
t := new(T)
fmt.Println(t.nextT == nil)
var ll LinkedList
ll = t
fmt.Println(ll.next() == nil)
}
Without checking nil (which I don't need to do) in next()I get
true
false
With this, I get the expected result.
true
true
Did I find a mistake or is this unexpected intention for some reason? Work on Windows with Go version 1 using a zip installation (without MSI)
source
share