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?
[HD Pg 182, Sec. 8.1.2 - returning-values-of-different-types-from-a-method]
Moderator: admin
-
- Posts: 2
- Joined: Sat Apr 25, 2020 12:43 pm
- Contact:
-
- 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]
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!
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.
Who is online
Users browsing this forum: pavvel and 33 guests