首次提交:初始化项目代码

This commit is contained in:
sunct
2026-07-31 15:18:32 +08:00
commit d6393266b0
193 changed files with 14287 additions and 0 deletions
+22
View File
@@ -0,0 +1,22 @@
package main
import "fmt"
// 处理任意类型(空接口参数)
func processAny(v interface{}) {
// 类型断言:判断实际类型
switch val := v.(type) {
case int:
fmt.Printf("整数:%d,平方:%d\n", val, val*val)
case string:
fmt.Printf("字符串:%q,长度:%d\n", val, len(val))
default:
fmt.Printf("未知类型:%T\n", val)
}
}
func main() {
processAny(10) // 整数:10,平方:100
processAny("hello") // 字符串:"hello",长度:5
processAny(3.14) // 未知类型:float64
}