-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathAutobox3.java
More file actions
28 lines (22 loc) · 843 Bytes
/
Autobox3.java
File metadata and controls
28 lines (22 loc) · 843 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package chapter12;
//Autoboxing/unboxing occurs inside expressions
public class Autobox3 {
public static void main(String[] args) {
Integer iOb, iOb2;
int i;
iOb = 100;
System.out.println("Original value of iOb: " + iOb);
//The following automatically unboxes iOb,
//performs the increments and then reboxes
//the result back into iOb
++iOb;
System.out.println("After ++iOb " + iOb);
//Here iOb is unboxed , the expression is evaluated
//and the result is reboxed and assigned to iOb2
iOb2 = iOb + (iOb / 3);
System.out.println("iOb2 after expression: " + iOb2);
//The same expression is evaluated ,but the result is not reboxed
i = iOb + (iOb / 3);
System.out.println("i after expression " + i);
}
}