Search code examples
govariablesinterface

what's the meaning of global variable _ which convers nil to an interface


I am trying to understand the effect of global variable _ from graph's source code like the belowing code, but at last I can't figure out what's the meaning.

type variable_ interface {
    cin()
}

type imple struct {
}

func (i *imple) cin() {
    fmt.Println("cout")
}

var (
    _ = variable_((*imple)(nil))
)

Solution

  • _ always means ignore in GO. the purpose of _ = variable_((*imple)(nil)) is to check at compile time if *impl implements variable_