经营者
运算符将操作数组合成表达式。
比较在其他地方讨论。对于其他二进制运算符,除非操作涉及移位或未类型化的常量,否则操作数类型必须相同。对于仅涉及常量的操作,请参见关于常量表达式的部分。
除移位操作外,如果一个操作数是未类型化的常量,而另一个操作数不是,则该常量将转换为另一种操作数的类型。
例如,使用“
*”(乘法)运算符,
package mainimport ( "time")func main() { // works - 1000 is an untyped constant // which is converted to type time.Duration time.Sleep(1000 * time.Millisecond) // fails - v is a variable of type int // which is not identical to type time.Duration var v = 1000 // invalid operation: i * time.Millisecond (mismatched types int and time.Duration) time.Sleep(v * time.Millisecond)}


