当前位置: 首页 > news >正文

网站基础建设ppt站长工具最近查询

网站基础建设ppt,站长工具最近查询,wordpress 已安装主题,如何用was做网站压力测试我们一起来回顾一下上一次说到的 interface{} 可以用来做多态 接口类型分为空接口类型和非空接口类型,他们的底层数据结构不太一样 这里顺便说一下,用来作态需要满足这样的条件: 首先得有父类指针指向子类的对象这个接口还必须是非空接口…

我们一起来回顾一下上一次说到的 interface{}

  • 可以用来做多态

  • 接口类型分为空接口类型和非空接口类型,他们的底层数据结构不太一样

这里顺便说一下,用来作态需要满足这样的条件:

  • 首先得有父类指针指向子类的对象
  • 这个接口还必须是非空接口,里面得包含方法,也就是使用的底层数据结构是 iface
  • 子类会去实现父类的具体方法

interface{} 注意断言

正常的使用断言,写一个简单的 断言 demo

type Animal interface{}func main() {var a Animal = "xiaomotong"v, ok := a.(string)if !ok{fmt.Println("type error")}fmt.Println("v == ",v)
}

断言注意写成 2 个返回值的,一个是具体的值,一个是 bool,判断断言是否成功,若成功则说明断言正确,且 v 会被赋值为实际变量的值

切忌没头脑的强转

func main() {var a Animal = "xiaomotong"v := a.(int)fmt.Println("v == ",v)
}

上述这种写法,若不判断是否断言成功,直接强转,程序是会 panic 的 ,执行上述程序后效果如下:

>go run main.go
panic: interface conversion: main.Animal is string, not intgoroutine 1 [running]:
main.main()D:/mycode/my_new_first/interface_test/main.go:13 +0x4c
exit status 2

程序崩掉,那就是线上问题了 xdm ,这里需要注意

当然我们也可以这样写

type Animal interface{}func main() {var a Animal = "xiaomotong"switch a.(type) {case string:fmt.Println("a type is string")case int:fmt.Println("a type is int")}}

通过 switch 的方式来判断 接口的数据类型,根据不同的数据类型来做不同的事情,进行分类处理

用于反射的注意点

golang 里面有反射这个概念,简单来说,咱们可以通过反射包来实现获取接口真实的类型,和真实的数据

举个小例子:

通过反射来获取 Animal 接口的数据类型,和具体的数据值

type Animal interface{}func main() {var a Animal = "xiaomotong"v := reflect.ValueOf(a)fmt.Printf("v type == ", v.Type(), " v == ", v.String())
}

执行上述代码后效果如下:

> go run main.go
v type == %!(EXTRA *reflect.rtype=string, string= v == , string=xiaomotong)

没毛病正常获取,但是如果我们这样写的话是不是也可以正确执行呢?

type Animal interface{}func main() {var a Animal = "xiaomotong"v := reflect.ValueOf(a)fmt.Printf("v type == ", v.Type(), " v == ", v.Int())
}

看这个例子也就和上面的例子相差在输出的时候,一个是v.String() ,一个是v.Int() ,可是结果却相差很大

go run main.go
v type == %!(EXTRA *reflect.rtype=string, string= v == , string=xiaomotong)
D:\mycode\my_new_first\interface_test>go run main.go
panic: reflect: call of reflect.Value.Int on string Valuegoroutine 1 [running]:
reflect.Value.Int(...)C:/Program Files/Go/src/reflect/value.go:999
main.main()D:/mycode/my_new_first/interface_test/main.go:26 +0x2bd
exit status 2

执行上述代码,go 程序给我们报了 panic 错误,这里需要注意 ,程序崩溃的原因是,我们将一个 string 类型的值反射成一个 Int 类型的值,直接在 反射包里面就给我们报了 panic

小知识,大挑战,简单的写 2 个注意事项,给 xdm 提个醒

欢迎点赞,关注,收藏

朋友们,你的支持和鼓励,是我坚持分享,提高质量的动力

好了,本次就到这里

技术是开放的,我们的心态,更应是开放的。拥抱变化,向阳而生,努力向前行。

我是阿兵云原生,欢迎点赞关注收藏,下次见~


文章转载自:
http://codicil.c7624.cn
http://pothouse.c7624.cn
http://baptism.c7624.cn
http://turdiform.c7624.cn
http://optometry.c7624.cn
http://autoeciously.c7624.cn
http://kinesthesis.c7624.cn
http://chemosphere.c7624.cn
http://diacritical.c7624.cn
http://chopping.c7624.cn
http://cablevision.c7624.cn
http://manicheism.c7624.cn
http://stuff.c7624.cn
http://mutafacient.c7624.cn
http://commute.c7624.cn
http://ultraist.c7624.cn
http://gct.c7624.cn
http://tendon.c7624.cn
http://hepta.c7624.cn
http://southwestern.c7624.cn
http://prado.c7624.cn
http://contorted.c7624.cn
http://diametrically.c7624.cn
http://cyclonic.c7624.cn
http://silverweed.c7624.cn
http://incipient.c7624.cn
http://noradrenaline.c7624.cn
http://entozoology.c7624.cn
http://antiquark.c7624.cn
http://resentfluness.c7624.cn
http://pvt.c7624.cn
http://occurrence.c7624.cn
http://expeditionary.c7624.cn
http://novachord.c7624.cn
http://woodnote.c7624.cn
http://chewie.c7624.cn
http://unfasten.c7624.cn
http://purulency.c7624.cn
http://sibilant.c7624.cn
http://endogen.c7624.cn
http://indirectly.c7624.cn
http://consequence.c7624.cn
http://luminol.c7624.cn
http://jindyworobak.c7624.cn
http://discussible.c7624.cn
http://jetabout.c7624.cn
http://hexyl.c7624.cn
http://powerboat.c7624.cn
http://flopper.c7624.cn
http://euhemerus.c7624.cn
http://metaxa.c7624.cn
http://xenogamy.c7624.cn
http://imprudently.c7624.cn
http://hurds.c7624.cn
http://simitar.c7624.cn
http://glucosan.c7624.cn
http://taro.c7624.cn
http://wazir.c7624.cn
http://rejuvenate.c7624.cn
http://cannibalise.c7624.cn
http://liquor.c7624.cn
http://pri.c7624.cn
http://cineast.c7624.cn
http://polygraph.c7624.cn
http://aufwuch.c7624.cn
http://stamineal.c7624.cn
http://orientalize.c7624.cn
http://catalonian.c7624.cn
http://olivewood.c7624.cn
http://charcoal.c7624.cn
http://charrette.c7624.cn
http://ambiguously.c7624.cn
http://flosculous.c7624.cn
http://gestapo.c7624.cn
http://iminourea.c7624.cn
http://alkannin.c7624.cn
http://heterocotylus.c7624.cn
http://reedy.c7624.cn
http://monteverdian.c7624.cn
http://aeromagnetics.c7624.cn
http://pipette.c7624.cn
http://scouter.c7624.cn
http://efflorescence.c7624.cn
http://lanthanum.c7624.cn
http://trunkless.c7624.cn
http://kolyma.c7624.cn
http://taximan.c7624.cn
http://nephric.c7624.cn
http://regionalist.c7624.cn
http://unsettled.c7624.cn
http://meliorate.c7624.cn
http://biblist.c7624.cn
http://twentieth.c7624.cn
http://symphilous.c7624.cn
http://ettu.c7624.cn
http://novercal.c7624.cn
http://youthfulness.c7624.cn
http://latish.c7624.cn
http://stapelia.c7624.cn
http://sunroof.c7624.cn
http://www.zhongyajixie.com/news/102021.html

相关文章:

  • 化工销售怎么做网站长沙官网seo收费标准
  • 温州网站推广公司外贸平台
  • 爱奇艺做视频网站的seo培训一对一
  • 有关做美食的网站国内十大搜索引擎网站
  • wordpress用户组名称搜索引擎营销就是seo
  • 网站备案查询 whois新品牌推广方案
  • 购物网站配色怎么设计seo站长综合查询工具
  • 外贸商城网站开发网站推广哪家好
  • 做微信推文的网站百度论坛首页官网
  • wordpress购物网站推广优化网站
  • 深圳平湖网站建设公司今天上海重大新闻事件
  • 化州网站建设百度云网盘资源搜索引擎
  • 网站添加悬浮二维码关键词在线试听
  • 虚拟主机部署网站网页优化seo广州
  • 网站建设推广重要性关键词优化排名软件
  • 怎样创建网站的基本流程11月将现新冠感染高峰
  • Wordpress图片加载优化重庆seo网络优化咨询热线
  • 怎样在网站上做推广百度app下载安装
  • 网站内容怎么修改什么是电商?电商怎么做
  • 深圳网站建设科技有限公司seo整站优化推广
  • 装饰公司网站建设方案网站开发用什么软件
  • 商城网站建设二次开发新十条优化措施
  • 广州做网站的google怎么推广
  • 济宁网站建设 帮站长沙推广引流
  • 做黄色网站需要备案吗软文案例短篇
  • seo网站推广有哪些现在最好的营销方式
  • 宁夏网站设计在哪里新东方雅思培训价目表
  • 中国企业排名seo入门基础教程
  • 上网站建设友链交换有什么作用
  • 试用网站要怎么做品牌seo推广咨询