参考链接 https://blog.csdn.net/tzs919/article/details/53571632 type是golang中非常重要的关键字,常见的就是定义结构体,但是其功能远不止是像c中那样只定义结构体,在golang中type关键字的功能可以说是非常丰富,通过参考相关的文章和源码,总结如下: 1 定义结构体 type person struct { name string //注意后面不能有逗号 age int } 2 类型定义,相当于定义一个别名 type name st
func pointer_test() { //空指针,输出为nil var p *int fmt.Printf("p: %v\n", p) //指向局部变量,变量值初始为0 var i int p = &i fmt.Printf("p: %v,%v\n", p, *p) //通过指针修改变量数值 *p = fmt.Printf("p: %v,%v\n", p, *p) //数组的初始化及输出 m := [], , } fmt.Print
什么是指针 指针是存储一个变量的内存地址的变量. 在上图中,变量 b 的值是 156,存储在地址为 0x1040a124 的内存中.变量 a 存储了变量 b 的地址.现在可以说 a 指向b. 指针的声明 一个指针变量指向了一个值的内存地址. 类似于变量和常量,在使用指针前你需要声明指针.指针声明格式如下: var var_name *var-type var-type 为指针类型,var_name 为指针变量名,* 号用于指定变量是作为一个指针.以下是有效的指针声明: var ip *int /
package main import( "fmt" _"sort" _"math/rand" ) //多态的特征是通过接口来实现的 //多态形式之一:多态参数 type Usb interface{ start() stop() } type Phone struct{ Name string } type Camera struct{ Name string } func (p Phone) start(){ fmt.Println(p.Na
map[string]interface{} is not the same as map[string]string. Type interface{} is not the same as type string. If they are both map[string]string: package main import "fmt" func main() { v := map[string]string{"hello": "world"
什么是反射 官方关于反射定义: Reflection in computing is the ability of a program to examine its own structure, particularly through types; it's a form of metaprogramming. It's also a great source of confusion. (在计算机领域,反射是一种让程序--主要是通过类型--理解其自身结构的一种能力.它是元编程的组成之一,同时