The “new” function changes in Go 1.26

2025-12-26

Here is how you can create a pointer to a boolean in Go 1.26:

// New way in Go 1.26
b := new(true)

This is equivalent to the older, more verbose method:

// Old way
val := true
b := &val

It works for all native types because the operand can be any expression. In addition to booleans, you can use it for:

Essentially, if you can write an expression that returns a value of type T, you can now pass that expression to new() to get a *T initialized with that value.

Tip

You can try it out today using gotip:

go install golang.org/dl/gotip@latest
gotip download