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

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

0

1 Answer 1

38

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

Sign up to request clarification or add additional context in comments.

2 Comments

what a genius move! Absolutelly nothing could go wrong! Every person that will modify type of the last argument will definetelly never forget to add the old type to previous argument. No, it could never happen. What a usefull addition to the language...
@SergeyKolesnik Golang is statically typed, so a wrong type will be easily detected.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.