3 ms·
With a 'generic' interface declaration we could remove the (type T) annotations. The compiler would still know what type parameters are needed (because they are
by irq-1 6y ago
With a 'generic' interface declaration we could remove the (type T) annotations. The compiler would still know what type parameters are needed (because they are used in the function prototype.)
// generic works like an interface
type T generic {
comparable // generic allows additional constraints
}
// we know the type parameters by the use of T
// (because T is generic type)
func Same(a, b T) T { ... }
// calls may still need to include the type parameters,
// but type inference will generally make them unnecessary
s := Same(type string)("hi","howdy")
s := Same("hi","howdy")