更新时间:2023-09-18 09:29:52
Java autoboxing /拆箱不会允许您取消引用基元,因此编译器会阻止它。您的编译器仍然知道 myInt
作为基元。在 jcp.org 上有一篇关于此问题的论文。
Java autoboxing/unboxing doesn't go to the extent to allow you to dereference a primitive, so your compiler prevents it. Your compiler still knows myInt
as a primitive. There's a paper about this issue at jcp.org.
在分配或参数传递期间,自动装箱主要是有用的 - 允许您将基元作为对象传递(反之亦然),或者将基元分配给对象(反之亦然)。
Autoboxing is mainly useful during assignment or parameter passing -- allowing you to pass a primitive as an object (or vice versa), or assign a primitive to an object (or vice versa).
所以不幸的是,你必须这样做:(荣誉帕特里克,我改用你的方式)
So unfortunately, you would have to do it like this: (kudos Patrick, I switched to your way)
Integer.toString(myInt);