This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Implication of autoboxing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Implication of autoboxing" Watch "Implication of autoboxing" New topic
Author

Implication of autoboxing

Rahul Kumar
Greenhorn

Joined: Aug 01, 2006
Posts: 16
Hi ,
Can anybody explain me here in the code the implication of autoboxing...

public class Ex {

Integer i;
int j;

public void go(){
//i=j;
j=i;
System.out.println("value of j :"+ j);
System.out.println("value of i :"+ i);
}

public static void main(String[] args) {
Ex obj=new StaticEx();
obj.go();

}

}

Regards,
Amazer
Gowher Naik
Ranch Hand

Joined: Feb 07, 2005
Posts: 643
[code]
public class Ex {

Integer i=0;
int j;

public void go(){
j=i; //line 7
System.out.println("value of j :"+ j);
System.out.println("value of i :"+ i);
}

public static void main(String[] args) {
Ex obj=new Ex();
obj.go();

}

}
/[code]
in code above i set Integer i=0;
then unboxing will occur at line 7.
in your code Integer i is null so there is NullpointException.
Boxing will occur when Integer i will refer to some Object.
But in your code Integer i donot refer to any object so boxing will not occur.
Gowher Naik
Ranch Hand

Joined: Feb 07, 2005
Posts: 643

in code above i set Integer i=0;
then unboxing will occur at line 7.
in your code Integer i is null so there is NullpointException.
Boxing will occur when Integer i will refer to some Object.
But in your code Integer i donot refer to any object so boxing will not occur.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Implication of autoboxing
 
Similar Threads
Boxing confusion
operator presedence
post(not)incremented?
Boxing n Auto boxing-marcus green