time.Millisecond * int confusion

前端 未结 5 533
臣服心动
臣服心动 2020-12-18 20:12

In the below example, if the 1000\'s are both int\'s (which I think they are) why would the bottom fail to compile?

//works
time.Sleep(1000 * time.Millisecon         


        
5条回答
  •  臣服心动
    2020-12-18 20:55

    You should convert to time.Duration (which underneath is an int64)

    var i = 1000
    time.Sleep(time.Duration(i) * time.Millisecond)
    

提交回复
热议问题