这样的声明虽然本身有效,但可能会使包的导出标识符不可用或造在读取代码时成混乱。
示例:
import "fmt"
import _ "fmt"
import iio "io"
func _() {
fmt.Println("demo")
demo := true
_, _ = iio.EOF, demo
}
func demo() (int, int) {
return 1, 2
}
func _() {
_, _ = iio.EOF, demo
fmt := "demo"
iio := 1
_, _ = iio, fmt
a, _ := demo()
_ = a
}
变量名 fmt
和 iio
与导入包的名称冲突。 为了之后不在代码中混淆他们,最好重命名这些变量。