<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>nil on Golang</title><link>https://golang.k5kc.com/tags/nil/</link><description>Recent content in nil on Golang</description><generator>Hugo -- gohugo.io</generator><language>en-us</language><lastBuildDate>Sun, 16 Aug 2020 00:15:00 +0530</lastBuildDate><atom:link href="https://golang.k5kc.com/tags/nil/index.xml" rel="self" type="application/rss+xml"/><item><title>nil channel VS closed channel</title><link>https://golang.k5kc.com/2020/08/16/nil-channel-vs-closed-channel/</link><pubDate>Sun, 16 Aug 2020 00:15:00 +0530</pubDate><guid>https://golang.k5kc.com/2020/08/16/nil-channel-vs-closed-channel/</guid><description>The zero value of channel type is nil, and the send and receive operations on a nil channel will always block. Check the following example:
package main import &amp;#34;fmt&amp;#34; func main() { var ch chan int go func(c chan int) { for v := range c { fmt.Println(v) } }(ch) ch &amp;lt;- 1 } The running result is like this:
fatal error: all goroutines are asleep - deadlock!
goroutine 1 [chan send (nil chan)]: main.</description></item><item><title>"nil slice" vs "nil map"</title><link>https://golang.k5kc.com/2020/08/16/nil-slice-vs-nil-map/</link><pubDate>Sun, 16 Aug 2020 00:10:00 +0530</pubDate><guid>https://golang.k5kc.com/2020/08/16/nil-slice-vs-nil-map/</guid><description>Slice and map are all reference types in Go, and their default values are nil:
package main import &amp;#34;fmt&amp;#34; func main() { var ( s []int m map[int]bool ) if s == nil { fmt.Println(&amp;#34;The value of s is nil&amp;#34;) } if m == nil { fmt.Println(&amp;#34;The value of m is nil&amp;#34;) } } The result is like this：
The value of s is nil The value of m is nil When a slice&amp;rsquo;s value is nil, you could also do operations on it, such as append:</description></item></channel></rss>