thomaswang
V2EX  ›  问与答

这个该怎么分析

  •  
  •   thomaswang · Jul 16, 2019 · 1636 views
    This topic created in 2491 days ago, the information mentioned may be changed or developed.
    package main
    
    import "fmt"
    
    func main() {
    	var a map[string]string
    	fmt.Println(a == nil)
    	f(a)
    }
    
    func f(in interface{}) {
    	fmt.Println(in == nil)
    }
    
    
    true
    false
    
    1 replies    2019-07-16 11:27:23 +08:00
    BCy66drFCvk1Ou87
        1
    BCy66drFCvk1Ou87  
       Jul 16, 2019
    go 中的 interface 包含 2 个指针,分别指向值的类型和实际的值。把一个 map[string]string 赋给 interface,interface 存了指向 string 类型的指针,因此不再是 nil。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3201 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 00:28 · PVG 08:28 · LAX 17:28 · JFK 20:28
    ♥ Do have faith in what you're doing.