import ( "fmt"// imported and not used: "fmt" "log"// imported and not used: "log" "time"// imported and not used: "time" ) func main() { } // 正确示例 // 可以使用 goimports 工具来注释或移除未使用到的包 import ( _"fmt" "log" "time" ) func main() { _ = log.Println...
// 错误示例 import ( "fmt" // imported and not used: "fmt" "log" // impor...
1// 错误示例2import(3"fmt"// imported and not used: "fmt"4"log"// imported and not used: "log"5"time"// imported and not used: "time"6)78funcmain(){9}101112// 正确示例13// 可以使用 goimports 工具来注释或移除未使用到的包14import(15_"fmt"16"log"17"time"18)1920funcmain(){...
// 错误示例import("fmt"// imported and not used: "fmt""log"// imported and not used: "log""time"// imported and not used: "time")funcmain(){}// 正确示例// 可以使用 goimports 工具来注释或移除未使用到的包import(_"fmt""log""time")funcmain(){_=log.Println_=time.Now} 1. 2....
/tmp/sandbox627475386/main.go:4:imported and not used:"fmt"/tmp/sandbox627475386/main.go:5:imported and not used:"log"/tmp/sandbox627475386/main.go:6:imported and not used:"time" Works: 代码语言:javascript 复制 packagemainimport(_"fmt""log""time")var_=log.Println ...
wangyishuaideMacBook-Pro:goStuwangyishuai$gorunhello.go#command-line-arguments./hello.go:2:8:importedandnotused:"fmt" go的常用关键字(25个) var和const :变量和常量的声明 var varName type 或者 varName : = value package and import: 导入 ...
/tmp/sandbox627475386/main.go:4: imported and not used: "fmt"/tmp/sandbox627475386/main.go:5: imported and not used: "log"/tmp/sandbox627475386/main.go:6: imported and not used: "time" 1. Works: package mainimport ( _ "fmt" "log" "time")var _ = log.Printlnfunc main() { _ ...
我们在程序的开发活跃阶段,常常要导入很多包,却暂不使用它,但是运行的时候go会报错imported and not used...,那么遇到这种情况可以使用空白标识符_。 例6 packagemainimport("geometry/rectangle")var_=rectangle.Area// 错误屏蔽器funcmain(){} var _ = rectangle.Area 这一行屏蔽了错误。运行时不会再报错。
[work@ hello2]#go run1.go# command-line-arguments./1.go:5:2:imported and not used:"time"./1.go:11:2:invalidcasev<3inswitchon v(mismatched typesboolandint)./1.go:13:2:invalidcasev<6inswitchon v(mismatched typesboolandint)[work@ hello2]# ...
.\test.go:3:8: imported and not used: "fmt" .\test.go:21:5: cannot use 200 + x1 (type int) as type int16 in assignment .\test.go:22:5: cannot use 200 + x1 (type int) as type int8 in assignment 基本数据类型和 string 之间的转换 ...