Possible Lossy conversion from long to int

后端 未结 6 678
借酒劲吻你
借酒劲吻你 2021-01-01 02:15

I wish to enter one int and another long ex: 1 and 1000000000, and now I wish to create an array of size 1000000000. And then at each index of arra

6条回答
  •  耶瑟儿~
    2021-01-01 03:00

    1. You cannot create an array with more than 2^31-1 entries, so you should use an int value when you do so (the compiler is simply warning you that the size will be truncated from long to int). 1000000000 is small enough to fit into int, so you basically have no reason to use long y in order to store this value in the first place.

    2. According to your description, the array itself is designated to store int values, so it doesn't need to be an array of long values.

    In short, you can and should change every long in your code to int.

提交回复
热议问题