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?
[HD Pg 87, Sec. 3.6.2 - creating-wrapper-objects]
Moderator: admin
-
- Posts: 221
- Joined: Mon Nov 26, 2018 2:43 pm
- Contact:
-
- Site Admin
- Posts: 10055
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: [HD Pg 87, Sec. 3.6.2 - creating-wrapper-objects]
Correct, the range is -128 to 127.
If you like our products and services, please help us by posting your review here.
-
- Posts: 202
- Joined: Mon Apr 02, 2018 8:40 am
- Contact:
Re: [HD Pg 87, Sec. 3.6.2 - creating-wrapper-objects]
Can integer literal be boxed into a Byte. You don't mention that.
It is important in this question: enthuware.ocajp.i.v8.2.1418
Code: Select all
Byte b = 1;
-
- Site Admin
- Posts: 10055
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: [HD Pg 87, Sec. 3.6.2 - creating-wrapper-objects]
It explains the general concept in Section 3.6.2 Point 3
Although there is an example of Byte inside the Note the above point:
There is only an example of Integer here. Will improve this to include examples of other types also."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. "
Although there is an example of Byte inside the Note the above point:
thank you!Byte b3 = 127; //autoboxing
If you like our products and services, please help us by posting your review here.
Who is online
Users browsing this forum: No registered users and 51 guests