Why can't a string be nil in Go?

前端 未结 4 983
予麋鹿
予麋鹿 2021-02-06 21:11

The program available on The Go Playground reads

package main

import \"fmt\"

func main() {
    var name string = nil
    fmt.Println(name)
}

4条回答
  •  庸人自扰
    2021-02-06 22:06

    In go string is a data type, it's no a pointer to an array like C/C++. As such you can't assign it to nil.

提交回复
热议问题