time.Millisecond * int confusion

前端 未结 5 525
臣服心动
臣服心动 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:50

    Go won't convert numeric types automatically for you. As far as I understand, 1000 isn't a numeric type until defined as one.

    The language specification says:

    Conversions are required when different numeric types are mixed in an expression or assignment. For instance, int32 and int are not the same type even though they may have the same size on a particular architecture.

提交回复
热议问题