Menu

Autoboxing in Java

Sharing is caring!

Critix always says that java is not fully object oriented language. Because, they always says we are using primitive data type here. No doubt java is fully object oriented language due to its boxing feature.

Auto Boxing:  This is the feature that comes in java 1.5 by which java compiler automatically converts the primitive data type into its corresponding wrapper class object. This auto conversion is not possible in java 1.4.

ohjkhjkJava applies auto boxing in two scenario

One is, during assignment.

1

Like, Integer i=10; or Character c=‘a’;

Here the Auto boxing applies by java compiler

Second is, at the time of passing as argument to a method.

For example:

int i=10;   and   String s=“10”;

2

 

s.equals(i);//equals method always looks for object . we passes the Primitive data type which auto converts to object. Here also auto boxing applies.

These are two cases where we need auto boxing. If I take both cases in java 1.4 then it is not possible. Here error at line 7.

blog

 

This is all about autobixing.

10 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

shares