Mega Code Archive

 
Categories / Java Book / 001 Language Basics
 

0091 Autoboxing and Methods

autoboxing occurs whenever a primitive type must be converted into an object; auto-unboxing takes place whenever an object must be converted into a primitive type. autoboxing/unboxing might occur when an argument is passed to a method, or when a value is returned by a method. For example, consider this example: public class Main { static int m(Integer v) { return v; // auto-unbox to int } public static void main(String args[]) { Integer iOb = m(100); System.out.println(iOb); } }