Ai
1 Star 0 Fork 0

清风/博客代码

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
main.go 706 Bytes
一键复制 编辑 原始数据 按行查看 历史
lidiqing 提交于 2024-07-12 19:58 +08:00 . 增加demo
package main
import (
"fmt"
"golang.org/x/exp/constraints"
)
func main() {
}
// Scale returns a copy of s with each element multiplied by c.
// This implementation has a problem, as we will see.
func Scale[E constraints.Integer](s []E, c E) []E {
r := make([]E, len(s))
for i, v := range s {
r[i] = v * c
}
return r
}
type Point []int32
func (p Point) String() string {
// Details not important.
return ""
}
// ScaleAndPrint doubles a Point and prints it.
func ScaleAndPrint(p Point) {
r := Scale(p, 2) //等价于r := Scale[int32](p, 2)
// 下面这行导致编译报错
// r.String undefined (type []int32 has no field or method String)
fmt.Println(r.String()) // DOES NOT COMPILE
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/qingfeng-169/blog-code.git
git@gitee.com:qingfeng-169/blog-code.git
qingfeng-169
blog-code
博客代码
master

搜索帮助