This is a creation in Article, where the information may have evolved or changed.
I. Overview
"_" can be simply understood as the assignment but no longer used, in the Golang used more, the use of a lot of occasions, a little summary;
Second, the scene
1. Import
1 Import "net/http/pprof"
The introduction of the package invokes the initialization function in the package, which only initializes the imported package and does not apply to other features in the package;
2, used in the return value
1 for _, V: = range Slice {}2 _, Err: = Func ()
Indicates that a value is ignored. A single function has multiple return values that are used to obtain a specific value
3. Use in variable
1 Interface {23} 4 5 struct {67} 8 9 var _ Interface = &t{}
The above is used to determine whether type T implements I, as a type assertion, and if T does not implement the excuse I, then the compilation error.
Example:
1 Package Main2 3Import"FMT"4 5Type InterfaceInterface {6 Stop ()7 }8 9Type BMWstruct {TenNamestring One } A -Func ( This*BMW) Stop () { -Fmt. Printf ("%s BMW stop.\n", This. Name) the } - -Type Carstruct { - Interface + } - + Func Main () { Ac: =car{ at&bmw{ -Name:"X5", - }, - } - c.stop () -}