A narrowing conversion is when putting a data type that can hold a bigger value into a data type that can hold at max a lesser value.
long l = 4L;
int i = (int)l;
However I don't understand why a short into a char is a narrowing conversion but I've the intuition it is related to signed/unsigned of those two datatypes but I can't explain why.
short s = 4; // short max value is 32767
char c = (char)s; // char max value is 65535
It looks like it would be a widening conversion or at the very least neither narrowing neither widening since they are both 16 bits and can hold the same number of values.
System.out.println((int)Character.MIN_VALUE); //0
System.out.println((int)Character.MAX_VALUE); //65535
System.out.println(Short.MIN_VALUE); //-32768
System.out.println(Short.MAX_VALUE); //32767
//65535 = 32768+32767
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…