<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                [TOC] ## 空接口定義 空接口是指沒有定義任何方法的接口類型。因此任何類型都可以視為實現了空接口。也正是因為空接口類型的這個特性,空接口類型的變量可以存儲任意類型的值。 ```go /* var i interface{} 等價于 type Any interface{} var i Any */ var i interface{} // 整型 i = 1 fmt.Printf("i: %v, type: %T\n", i, i) // 浮點數 i = 1.35 fmt.Printf("i: %v, type: %T\n", i, i) // 字符串 i = "jiaxzeng" fmt.Printf("i: %v, type: %T\n", i, i) // 布爾值 i = true fmt.Printf("i: %v, type: %T\n", i, i) // 切片 i = []string{"jiaxzeng", "xiaodunan"} fmt.Printf("i: %v, type: %T\n", i, i) // map 映射 i = map[int]string{1: "jiaxzeng"} fmt.Printf("i: %v, type: %T\n", i, i) // 指針 x := "jiaxzeng" i = &x fmt.Printf("i: %v, type: %T\n", i, i) // 運行結果: // i: 1, type: int // i: 1.35, type: float64 // i: jiaxzeng, type: string // i: true, type: bool // i: [jiaxzeng xiaodunan], type: []string // i: map[1:jiaxzeng], type: map[int]string // i: 0xc000010290, type: *string ``` ## 空接口應用 ### 空接口作為函數的參數 使用空接口實現可以接收任意類型的函數參數。 ```go func showType(x interface{}) { fmt.Printf("x is value: %v, x is type: %T\n", x, x) } func main() { showType(1) showType("jiaxzeng") showType(1.5) showType([]string{"jiaxzeng"}) showType(map[string]string{"name": "jiaxzeng"}) x := 18 showType(&x) } // 運行結果: // x is value: 1, x is type: int // x is value: jiaxzeng, x is type: string // x is value: 1.5, x is type: float64 // x is value: [jiaxzeng], x is type: []string // x is value: map[name:jiaxzeng], x is type: map[string]string // x is value: 0xc0000ba010, x is type: *int ``` ### 空接口作為map的值 使用空接口實現可以保存任意值的字典。 ```go m := make(map[string]interface{}) m["name"] = "jiaxzeng" m["age"] = 18 m["course"] = []string{"Kubernetes", "Golang", "Python"} fmt.Printf("m: %v\n", m) ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看