[HD Pg 182, Sec. 8.1.2 - returning-values-of-different-types-from-a-method]
Posted: Wed Jun 03, 2020 4:48 pm
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?
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?