Nil interface values

A nil interface value holds neither value nor concrete type.

Calling a method on a nil interface is a run-time error because there is no type inside the interface tuple to indicate which concrete method to call.

nil-interface-values.go

  1. package main
  2. import "fmt"
  3. type I interface {
  4. M()
  5. }
  6. func main() {
  7. var i I
  8. describe(i)
  9. i.M()
  10. }
  11. func describe(i I) {
  12. fmt.Printf("(%v, %T)\n", i, i)
  13. }