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

go switch 与 interface

go switch 与 interface

  • 前言

前言

github.com/google/cel-go/common/types/ref

type Val interface {// ConvertToNative converts the Value to a native Go struct according to the// reflected type description, or error if the conversion is not feasible.ConvertToNative(typeDesc reflect.Type) (interface{}, error)// ConvertToType supports type conversions between value types supported by// the expression language.ConvertToType(typeValue Type) Val// Equal returns true if the `other` value has the same type and content as// the implementing struct.Equal(other Val) Val// Type returns the TypeValue of the value.Type() Type// Value returns the raw value of the instance which may not be directly// compatible with the expression language types.Value() interface{}
}

当我们实现了一个interface时,使用swtich case去判断,会命中哪条结果?

switch i := v.(type) {case ref.Val:return resolveType(i.Value())case *CustomType:return resolveType(i.Value())default:}

经过测试发现,谁的case靠前,会命中谁,哪怕CustomType有一些私有方法
后面空了看看switch 底层实现。。

http://www.lryc.cn/news/383641.html

相关文章:

  • BaseMapper 接口介绍
  • HAL-Cubemax定时器使用记录
  • 同时使用磁吸充电器和Lightning时,iPhone充电速度会变快吗?
  • 零成本搭建个人图床服务器
  • SpringBoot 搭建sftp服务 实现远程上传和下载文件
  • IDEA中使用leetcode 刷题
  • 华为海思CPU解读
  • 中介子方程三十三
  • 今年哪两个行业可能有贝塔?
  • 嵌入式软件开发工具使用介绍
  • 【TB作品】MSP430G2553,单片机,口袋板, 交通灯控制系统
  • windows 安装 Kubernetes(k8s)
  • C语言 | Leetcode C语言题解之第189题轮转数组
  • 【安全审核】音视频审核开通以及计费相关
  • 【实战】Spring Cloud Stream 3.1+整合Kafka
  • java之可变字符串之append方法
  • [保姆级教程]uniapp自定义导航栏
  • 项目训练营第二天
  • 考研数学一有多难?130+背后的残酷真相
  • vue2脚手架笔记总结1
  • 校园巡礼:一周只上四天课,入学即发钱?深圳理工大学,开局即王炸
  • 免交互 实验
  • Sublime Text 设置
  • spire.Pdf 将pdf转成image
  • 仓颉编程语言 -- 初识(一)
  • 前端JS必用工具【js-tool-big-box】学习,数值型数组的正向排序和倒向排序
  • python web框架哪家强?Flask、Django、FastAPI对比
  • Mybatis plus:IService接口
  • 时序分析基本概念介绍——min pulse width 最小脉冲宽度
  • PHP原生代码生成pdf---解决中文乱码问题