Skip to main content
Journey Uncommon Logo
JourneyUncommon
mediumGogenerics type parametersSingle-choice MCQ

Why does this generic function fail to compile, and what constraint construct fixes it?

func Sum[T any](xs []T) T { var total T for _, x := range xs { total += x } return total }