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);
}
}
Home
Java Book
Language Basics
Java Book
Language Basics
Autoboxing Autounboxing:
- Autoboxing and auto-unboxing
- Autoboxing and Methods
- Autoboxing/Unboxing in Expressions