[HD Pg 182, Sec. 8.1.2 - returning-values-of-different-types-from-a-method]

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

Moderator: admin

Post Reply
addy12345
Posts: 2
Joined: Sat Apr 25, 2020 12:43 pm
Contact:

[HD Pg 182, Sec. 8.1.2 - returning-values-of-different-types-from-a-method]

Post by addy12345 »

Hi ,
need some clarity on below sentence from the book .
"Java allows a return value to be a reference to a wrapper class if the return type is of a primitive type of the same or smaller type" .

short m1()
{
return new Integer(1); //compile error
}
above sentence telling that , we can return a wrapper class reference if the return type is primitive type of smaller type? but actually it is not possible .am i missing something?

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

Re: [HD Pg 182, Sec. 8.1.2 - returning-values-of-different-types-from-a-method]

Post by admin »

You are right. That's a mistake. It should say same or larger type.
The next statement is also incorrect. It should say, "The reverse is also allowed but only when the method's return type is a wrapper of the same type as the type of the primitive value being returned -"

Adding to errata.

thank you for your feedback!
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: pavvel and 33 guests