Introduction to Go Generics
Type Safety
Using interface{} in the Past
Types for a and b are checked only at runtime, increasing the possibility of errors.
func Add(a, b interface{}) interface{} {
return a.(int) + b.(int) // Requires type assertion and is unsafe
}
Generic ...
ganhua.wang8 min read