Must autoboxing call valueOf?

Sam Munkes sam.munkes at gmail.com
Thu Aug 6 00:48:10 UTC 2015


Thanks Jonathan,

So those statements are not guaranteed to be true, since the JLS does not
mandate that valueOf() be used (it only mandates ranges where 2 boxing
conversions will return the same instance).

On Wed, Aug 5, 2015 at 5:34 PM, Jonathan Gibbons <
jonathan.gibbons at oracle.com> wrote:

> Sam,
>
> The relevant text would appear to be in JLS 5.1.7, Boxing Conversion.
>
> https://docs.oracle.com/javase/specs/jls/se8/html/jls-5.html#jls-5.1.7
>
> -- Jon
>
>
>
>
> On 08/05/2015 05:28 PM, Sam Munkes wrote:
>
> Hi -
>
> A colleague of mine was wondering if the following statements are
> guaranteed to be true:
> ((Boolean)true) == Boolean.TRUE
> ((Boolean)true) == Boolean.valueOf(true)
> ((Integer)1) == Integer.valueOf(1)
>
> javac does indeed call valueOf() for autoboxing, but is this behavior
> mandated by the JLS?
>
> The answers on stackoverflow
> http://stackoverflow.com/questions/31445024/does-autoboxing-call-valueof agree
> that although in practice the compilers use valueOf(), the JLS does not
> mandate it.
>
> Does anyone here know more on the subject?
>
> Thanks
>
> Sam
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/compiler-dev/attachments/20150805/7157fddf/attachment.html>


More information about the compiler-dev mailing list