[HD Pg 87, Sec. 3.6.2 - creating-wrapper-objects]

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
OCAJO1
Posts: 221
Joined: Mon Nov 26, 2018 2:43 pm
Contact:

[HD Pg 87, Sec. 3.6.2 - creating-wrapper-objects]

Post by OCAJO1 »

Page 89 - "The valueOf methods of Byte, Short, Char, Integer, and Boolean guarantee that they will return cached objects for the same ranges given above"

Page 90 - "Integer i1 = Integer.valueOf(128);
Integer i2 = Integer.valueOf(128); //i1 and i2 may or may not refer to the same Integer instance"

Just to double check, the word guarantee does not apply here, because the value is higher than 127?

admin
Site Admin
Posts: 10046
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: [HD Pg 87, Sec. 3.6.2 - creating-wrapper-objects]

Post by admin »

Correct, the range is -128 to 127.
If you like our products and services, please help us by posting your review here.

flex567
Posts: 202
Joined: Mon Apr 02, 2018 8:40 am
Contact:

Re: [HD Pg 87, Sec. 3.6.2 - creating-wrapper-objects]

Post by flex567 »

Can integer literal be boxed into a Byte. You don't mention that.

Code: Select all

Byte b = 1;
It is important in this question: enthuware.ocajp.i.v8.2.1418

admin
Site Admin
Posts: 10046
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: [HD Pg 87, Sec. 3.6.2 - creating-wrapper-objects]

Post by admin »

It explains the general concept in Section 3.6.2 Point 3
"All it means is that if you assign a primitive value to a wrapper variable, the
compiler will automatically box the primitive value into a wrapper object. "
There is only an example of Integer here. Will improve this to include examples of other types also.


Although there is an example of Byte inside the Note the above point:
Byte b3 = 127; //autoboxing
thank you!
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 50 guests