package main

import "fmt"

func sumInts(list []interface{}) int {
	sum := 0
	for _, v := range list {
		if n, ok := v.(int); ok { // 关键断言
			sum += n
		}
	}
	return sum
}

func main() {
	data := []interface{}{"a", 1, 2.5, 3, "b", 4, true}
	fmt.Println("sum =", sumInts(data)) // 期望 1+3+4 = 8
}
