go1.27.0: generic methods, encoding/json/v2 package, uuid package, faster memory allocation, goroutine leak profiles
Changes to the language
o 1.27 now supports generic methods: a method declaration may declare its own type parameters. This widely anticipated change allows adding generic functions within the namespace of a particular data type where before one had to declare such functions with a scope of the entire package.
As an example, math/rand/v2 now also declares a generic method with signature (*Rand) N[Int intType](Int) Int, whereas previously it had just a generic function N[Int intType](Int) Int (see below for details). Note that methods of interfaces may not declare type parameters nor can interface methods be implemented by generic methods.
A key in a struct literal may now be any valid field selector for the struct type, not just a (top-level) field name of the struct.
Function type inference has been generalized to apply in all contexts where a generic function is assigned to a variable of (or converted to) a matching function type.
Did you enjoy this article?
Recommend it — Standard Reader surfaces well-loved writing to more readers across the network.