The expression of type x is boxed into X?
Asked Answered
T

1

10

I'm a little confused by a warning that my Eclipse IDE is currently writing next to every expression where types are autoboxed or autounboxed:

The expression of type x is boxed into X

The expression of type X is unboxed into x

Is this a warning I should react on? I thought autoboxing was a Java language feature - but now I seem to get warnings everytime this feature is used.

Toughie answered 18/2, 2011 at 8:31 Comment(3)
You can turn this warning off by going to "Window -> Preferences -> Java -> Compiler -> Errors/Warnings", and then unchecking "Boxing and unboxing conversions" under "Potential programming problems".Marchpast
Auto-unboxing is something you might occasionally be wary of. This can cause unexpected nullpointerexceptions.Casern
Hopefully they'll separate autoboxing from auto-unboxing: bugs.eclipse.org/bugs/show_bug.cgi?id=163065Biradial
H
6

I don't think Eclipse does this by default (mine does not), but you can turn it on or off using Preferences > Java > Compiler > Errors/Warnings > Potential programming problems > Boxing and Unboxing Conversions.

It should be "Ignore" unless you really want to know about this.

Henri answered 18/2, 2011 at 8:37 Comment(2)
So that's really only an Eclipse notice and not really a Java warning?Toughie
I don't believe javac will ever flag this situtation, but unlike errors, warnings are fudgible. Many have to do with code style. Some people just prefer to write an explicit cast/box/unbox, etc. Eclipse Java compiler can report on a number of problems which don't stand in the way of compilation but the user may want to know about. You have the option of telling Eclipse whether any particular one of these should be error, warning or ignore severity. Eclipse Java compiler can identify many more such conditions than javac.Steere

© 2022 - 2024 — McMap. All rights reserved.