go 实现泛型_在Go中生成泛型类型的实现

go 实现泛型

Go has strong, static types and it does not support generics, so how can we define general purpose data structures and algorithms that can be applied to more than one type? interface{}s are not the solution, as they require casting and we lose a lot of the advantages of having strong, static typing. The solution is code generation, as it allows to get compile-time checks and safety, and higher performance.

Go具有强大的静态类型,并且不支持泛型,那么我们如何定义可应用于多种类型的通用数据结构和算法? interface{}并不是解决方案,因为它们需要强制转换,而我们失去了拥有强大的静态类型的许多优点。 解决方案是代码生成 ,因为它可以获取编译时检查和安全性以及更高的性能。

I didn’t find this information easily accessible when searching for code generation topics, but I stumbled on more complex use cases and scenarios, so here it is, explained in plain english.

在搜索代码生成主题时,我发现这些信息不容易获得,但是我偶然发现了更复杂的用例和场景,因此这里用简单的英语进行了解释。

问题: (Problem:)

I want to implement a data structure (the same applies to an algorithm) in the most general possible way with Go, and generate type-specific implementations that I can easily reuse.

我想用Go 以最通用的方式 实现数据结构 (对算法也是如此),并生成可以轻松重用的特定于类型的实现

解: (Solution:)

Using genny, this couldn’t

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值