Go 1.7.3 supports function overloading!

Nerdmaster

This is now valid syntax in Go:

var value interface{}

//+overloaded
func setValue(x int) {
	value = x
}

//+overloaded
func setValue(x string) {
	value = x
}

//+overloaded
func setValue(x int, y string) {
	value = fmt.Sprintf("%d %s", x, y)
}

If you don’t believe me, check out the source code on the Go playground.

All posts