Why is implicit conversion from int to Long not possible?

后端 未结 3 398
攒了一身酷
攒了一身酷 2021-01-05 02:14

I can implicitly conver int to long and long to Long. Why is it not possible to implicitly convert int to Long? Why can\'t Java do the implicit conversion on the last line o

3条回答
  •  迷失自我
    2021-01-05 02:22

    Boxing only works with primitives. That's why.

    Try this: Long.valueOf(int);

    Documentation

提交回复
热议问题