The widening conversion is permitted in the following cases:
byte to short, int, long, float, or double
Short to int, long, float, or double
char to int, long, float, or double
int to long, float, or double
long to float or double
float to double
So we have widening as opposed to narrowing, the latter requires an explicit cast.
Palash Nandi wrote: . . . A bit of googling helped here. . . .
I am afraid the first link didn’t help at all. It has bits missing. Your second link is more useful, particularly when it says that casting reference types is different from casting primitives. It would have been a good idea to use a different word from “cast” for reference types.
Widening can be applied to reference types, as you will find if you read the Java Language Specification (JLS). You can see the other types of conversion in the same section of the JLS.
The JLS doesn’t use the term upcast, so we shall presume the correct term is widening conversion of a reference type.
Campbell Ritchie wrote:What you showed there is a narrowing primitive conversion.
Yes. I saw JLS, you are referring to this
In every conversion context, only certain specific conversions are permitted. For convenience of description, the specific conversions that are possible in the Java programming language are grouped into several broad categories:
Campbell Ritchie wrote:Primitive casts are totally different from reference casts, which is what the original question was about.
I think Rus asked if the example was of type widening or upcasting : Then the answer is both. Since widening and upcasting can refer to reference as well as primitive. Though the word upcast is never used in the JLS.
A TubeBulb May light slowely... But it lights the Brightest..
Palash Nandi wrote: . . . I think Rus asked if the example was of type widening or upcasting : Then the answer is both. Since widening and upcasting can refer to reference as well as primitive. Though the word upcast is never used in the JLS.
I have never heard anybody call a widening primitive conversion an upcast before. I have only heard upcast and downcast used of reference types. Otherwise: agree
Why is the word "abbreviation" so long? And this ad is so short?