Posts

Showing posts with the label collection

Autoboxing Sucks !

Introduction Java 1.5 released a lot of features - notable among them were Annotation, Generics, Varargs, for-each loops and an ease-of-coding shortcut called 'Autoboxing'. Autoboxing is a way to automatically convert the primitive types to its corresponding 'Wrapper Classes'. The primary reason why we would like to convert the primitives to a wrapper class is a wrapper class' ability to hold null values. The primitives can never be null. Things were simple before Java 1.5 in the sense that when a programmer needed an object that can hold nulls as well, they would go for the wrapper classes and when they knew that it will always hold a value they would go for a primitive type declaration. One example for this is a bean class that holds a corresponding table value. Some of the values of a table row can be null. For those fields the value is declared as as a wrapper class for the database fields that will always hold a value we usually define them as primitives. ...