5
Go 官方的新教程:泛型 和 fuzz test
source link: https://www.v2ex.com/t/839838
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Go 官方的新教程:泛型 和 fuzz test
12 条回复 • 2022-03-13 07:11:07 +08:00
haoliang 1 天前 2
```
type Number interface {
int64 | float64
}
```
我之前一直以为 interface 仅是对行为的约束,现在也可以代表类型了
type Number interface {
int64 | float64
}
```
我之前一直以为 interface 仅是对行为的约束,现在也可以代表类型了
aristotll 1 天前 6
还没有说吗我先来,go 不需要泛型 😠
keepeye 1 天前 1
已经用上了,写了一些工具函数感觉还可以
giiiiiithub 1 天前 3
他们不是说:go 不需要泛型吗?
看不懂了,真的看不懂了。我是说看不懂邪教信徒了,不是说看不懂 go 了。
看不懂了,真的看不懂了。我是说看不懂邪教信徒了,不是说看不懂 go 了。
keepeye 1 天前
// 从一个 slice 中随机取一个元素
func Choice[T any](items []*T) *T {
if len(items) == 0 {
return nil
}
return items[rand.Intn(len(items))]
}
func Choice[T any](items []*T) *T {
if len(items) == 0 {
return nil
}
return items[rand.Intn(len(items))]
}
james122333 21 小时 16 分钟前 via Android
泛型虽然好用 但无疑会增加代码複杂度
事先定义好也不是不可以 希望不要作为隐藏实现细节的框架使用 代码世界坑还不够多吗
事先定义好也不是不可以 希望不要作为隐藏实现细节的框架使用 代码世界坑还不够多吗
kunkunzhang 21 小时 5 分钟前
@james122333 事先定义好的,要么重载,要么像 js 一样弱类型,泛型不就是为了解决这种问题的吗
james122333 20 小时 46 分钟前 via Android
avastms 20 小时 23 分钟前
🤮 可读性劝退
yin1999 19 小时 1 分钟前 via Android
现在是 15 个 issues 🙃
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK