|
|
|
|
|
by jamespwilliams
1652 days ago
|
|
You can use type parameters in functions, but not methods. Methods are functions which have a receiver, so: // This is a function, you can use type parameters here:
func Foo[T any](g T) { ... }
type bar struct {}
// This is a method, you can't use type parameters here:
func (b bar) Foo[T any](g T) { ... }
In the second case, "Foo" is a method which has a "bar" instance as a receiver.I've edited my original post to make it a bit clearer. |
|