nodakai
nodakai

Reputation: 8001

Golang function parameter without type?

func Match(pattern, name string) (matched bool, err error)

Why does pattern not have to have a type (like pattern string)?

Upvotes: 29

Views: 8670

Answers (1)

user94559
user94559

Reputation: 60133

Per https://tour.golang.org/basics/5:

When two or more consecutive named function parameters share a type, you can omit the type from all but the last.

In this example, we shortened

x int, y int

to

x, y int

Upvotes: 38

Related Questions