浏览 169
分享
Top-level Variable Declarations
At the top level, use the standard var
keyword. Do not specify the type,unless it is not the same type as the expression.
Bad | Good |
---|---|
|
|
Specify the type if the type of the expression does not match the desired typeexactly.
- type myError struct{}
- func (myError) Error() string { return "error" }
- func F() myError { return myError{} }
- var _e error = F()
- // F returns an object of type myError but we want error.
评论列表