Radar · Go · Archive · Week 22 · May 25 – 31, 2026
Generic methods for Go
Worth knowinglanguage
- What changed
- The language spec now allows methods on concrete types to be generic, enabling type parameters on method receivers.
- Production impact
- The source does not say.
- Try it
- Write a struct with a generic method and compile with a development branch that includes the change.
- Source
- github.com/golang/go/issues/77273
Understand it, then run it
Concrete methods in Go are functions that belong to a type, like func (s *S) m(x int). Until now, those methods could not declare their own type parameters; only the type of the receiver could be generic. The change lets you write a method that itself has type parameters, e.g. func (*S) m[T any](x T). You can call such a method with an explicit type argument, s.m[int](42), or let the compiler infer it, s.m(42).
Run it now
// This program runs on Go 1.27.1.
// It demonstrates that generic methods are not yet supported: attempting to
// declare a method with type parameters would produce a compile‑time error.
// Instead we simply print a message explaining the current limitation.
package main
import "fmt"
func main() {
// In Go 1.27.1 a declaration like
// func (s S) m[T any](x T) {}
// would fail to compile with "generic methods are not allowed".
// Since the feature is not yet shipped, we show the current state.
fmt.Println("Generic methods are not supported in Go 1.27.1")
}
What it printed when we ran it on Go 1.27.1
Generic methods are not supported in Go 1.27.1
Run sends this program (for Solidity, the contract and its tests) to our own sandbox, where it is compiled and run once, with no network, and what it printed or the test report comes back here. Nothing is kept. Runs are counted per visitor for the day so everyone gets a turn; the details are on the legal page.
Written by gpt-oss-20b from the linked source · claims checked against the sources · archive, not individually reviewed