字符串不能被賦為"空"
package main
func main() {
var x string = nil //error
if x == nil { //error
x = "default"
}
}
./hello.go:4: cannot use nil as type string in assignment
./hello.go:6: invalid operation: x == nil (mismatched types string and nil)
看來nil并不代表空的字符串
package main
func main() {
var x string //defaults to "" (zero value)
if x == "" {
x = "default"
}
}
發(fā)現(xiàn)nil并不能進行比較操作
invalid operation: nil == nil (operator == not defined on nil)