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.

B.E.
  • 5,080
  • 4
  • 35
  • 43
  • 1
    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". – Oliver Charlesworth Feb 18 '11 at 08:37
  • 2
    Auto-unboxing is something you might occasionally be wary of. This can cause unexpected nullpointerexceptions. – extraneon Feb 18 '11 at 08:46
  • Hopefully they'll separate autoboxing from auto-unboxing: https://bugs.eclipse.org/bugs/show_bug.cgi?id=163065 – Kyle Sep 06 '13 at 03:18

1 Answers1

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.

Thilo
  • 257,207
  • 101
  • 511
  • 656
  • So that's really only an Eclipse notice and not really a Java warning? – B.E. Feb 18 '11 at 08:54
  • 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. – Konstantin Komissarchik Feb 18 '11 at 21:30