Why can I pass 1 as a short, but not the int variable i?

后端 未结 7 1856
谎友^
谎友^ 2020-12-07 16:18

Why does the first and second Write work but not the last? Is there a way I can allow all 3 of them and detect if it was 1, (int)1 or i passed in? And really why is one allo

相关标签:
7条回答
  • 2020-12-07 16:59

    I believe it is because you are passing in a literal/constant in the first two, but there is not automatic type conversion when passing in an integer in the third.

    Edit: Someone beat me to it!

    0 讨论(0)
提交回复
热议问题