Andrew McDonough

Please note: This page is imported from my wiki, which hasn't been updated in over 10 years. Some of the formatting was lost during the import. I'll try to get around to fixing it someday.

Autoboxing

  • Autoboxing is a programming term for automatically treating a primitive type as an object without having to create the wrapper object.
  • Autoboxing is used in .NET and will be available in Java from J2SE 5.0
  • This will allow to use primitive types in Java collections.

Unboxing is the opposite, but achieves the same goal - less code for the same functionality. It allows you to treat an Object wrapper for a primitive type as the primitive it represents, without calling a getValue method.

e.g.

Integer x = new Integer(2); Integer y = new Integer(4); Integer z = x + y; // The value of z is now 6


Andrew McDonough

Andrew McDonough is a consultant CTO and software developer, currently based between Berlin and London.

Follow Andrew on Twitter or Connect on LinkedIn