By Ada Brackett — Solnyxus editorial Team.
Go generic methods arrived in Go 1.27 (August 2026). Since generics landed in Go 1.18, a method could use its type's parameters but could not declare new ones. Go 1.27 removes that limit: a method declaration may now declare its own type parameters. This post shows what that means, with a lab you can run in ten minutes. I checked the release notes on go.dev on 1 November 2026 and ran every snippet on Go 1.27.2.
What changed
Before 1.27, if you had a List[T] and wanted to turn it into a List[U], you wrote a package-level function: Map[T, U any](l *List[T], f func(T) U) *List[U]. It worked, but it lived outside the type, and callers had to remember it existed.
Now the method can carry its own type parameter. The standard library uses this too: math/rand/v2 now declares (*Rand) N[Int intType](Int) Int as a method, next to the existing package-level N function.
The lab: a List with its own Map
Make a folder and a module that targets Go 1.27:
module example.com/genmeth
go 1.27
The go 1.27 line matters: older language versions reject the syntax.
Now main.go:
package main
import (
"fmt"
"math/rand/v2"
"strings"
)
// List is a small ordered collection of T.
type List[T any] struct {
items []T
}
func (l *List[T]) Push(v T) { l.items = append(l.items, v) }
// Map is a generic method: it brings its own type parameter, U.
func (l *List[T]) Map[U any](f func(T) U) *List[U] {
out := &List[U]{items: make([]U, 0, len(l.items))}
for _, v := range l.items {
out.items = append(out.items, f(v))
}
return out
}
func main() {
words := &List[string]{}
for _, w := range []string{"gopher", "ferris", "tux"} {
words.Push(w)
}
lengths := words.Map(func(s string) int { return len(s) })
shout := words.Map[string](strings.ToUpper)
fmt.Println(lengths.items)
fmt.Println(shout.items)
r := rand.New(rand.NewPCG(1, 2))
fmt.Println(r.N(int64(6)) < 6)
}
T comes from the receiver; U is declared on Map itself, in square brackets after the method name.
Run it:
go run .
You should see:
[6 6 3]
[GOPHER FERRIS TUX]
true
The first line is the lengths, the second the upper-cased words, and the third proves the new rand method works.
How the type arguments get filled in
Look at the two calls to Map. The first one, words.Map(func(s string) int { ... }), never says what U is. Go infers it from the function you passed: it returns int, so U is int.
The second, words.Map[string](strings.ToUpper), spells it out. You rarely need to, but it is useful when inference has nothing to go on, or when you want the code to say it plainly.
Go 1.27 also widened function type inference in general: it now applies wherever a generic function is assigned to a variable of, or converted to, a matching function type.
The rule that still holds: interfaces
Interfaces did not get this feature. The release notes are clear: methods of interfaces may not declare type parameters, and interface methods cannot be implemented by generic methods.
Try it and the compiler says so:
type Mapper interface {
Map[U any](f func(int) U) []U
}
On Go 1.27.2 that fails with interface method must have no type parameters.
So a generic method is a convenience for the concrete type. It does not satisfy an interface, and you cannot ask for one through an interface. If you need dynamic dispatch, keep a non-generic method for the interface.
When to reach for it
Use a generic method when the operation belongs to the type: Map, Filter into another element type, a typed Get on a cache, a converter on a config struct. It keeps the API in one place, and your editor's autocomplete finds it after the dot.
Keep a package-level function when the operation spans several types equally, or when you need it to work through an interface.
Two smaller 1.27 changes worth knowing
A key in a struct literal may now be any valid field selector for the struct type, not just a top-level field name. And the standard library has a new uuid package that generates and parses UUIDs.
Try this next
Add a Filter method that keeps the element type, then a Reduce[A any] generic method that folds the list into one value of type A. Then open math/rand/v2 in go doc and compare the N function with the new (*Rand).N method.
Read the full notes at https://go.dev/doc/go1.27 (opens in a new tab).
Cloud
More like this
Cloud
Build a Tiny JSON API With Axum: Rust on the Web in Fifteen Minutes
Your Rust programs have been talking to the terminal. Time they talked to the internet. Build a notes API with Axum, with routes, JSON in and out, shared state and proper 404s, in about 50 lines.
Cloud
Ollama Review: Running Local LLMs on Your Own Machine, No Cloud Required
What if your AI assistant lived in your basement instead of someone else's data centre? A review of Ollama: how to run local LLMs with it, what hardware you really need, the API that makes it useful, and where it falls short.
Cloud
Async Rust With Tokio: Build an Echo Server That Juggles a Thousand Clients
One waiter, forty tables, and nobody waits for their soup. That's async. Learn async Rust with Tokio by building a 30-line TCP echo server, then meet the one mistake that freezes the whole restaurant.