4、Add a generic function to handle multiple types(添加一个泛型函数 用来处理多种类型)
5、Remove type arguments when calling the generic function(调用泛型函数时移除类型参数)
6、Declare a type constraint(声明类型范围/约束)
7、Conclusion(结束语)
8、Completed code(最终代码)
Note: This is beta content.(重点: 这只是测试办的内容)
原文:
翻译:
Note: For other tutorials, see Tutorials.(注意:有关其他教程,请参阅教程。)
Note: If you prefer, you can use the Go playground in “Go dev branch” mode to edit and run your program instead.(如果您愿意,您可以在“Go dev branch”模式下使用 Go playground 来编辑和运行您的程序。)
1、Prerequisites(前提)
An installation of Go 1.18 Beta 1 or later. For installation instructions, see Installing and using the beta.(Go 1.18 Beta 1 或更高版本的安装。 有关安装说明,请参阅安装和使用测试版。)
A tool to edit your code. Any text editor you have will work fine.(编辑代码的工具. 任何文本编辑器都可以正常工作。)
A command terminal. Go works well using any terminal on Linux and Mac, and on PowerShell or cmd in Windows. (命令终端。 Go 适用于 Linux 和 Mac 上的任何终端,以及 Windows 中的 PowerShell 或 cmd。)