Java learning: possible lossy conversion from int to short

fault code

 short s = 5; s = s - 2; 
 error: incompatible types: possible lossy conversion from int to short         s = s - 2;               ^ 1 error 

Correct code

 // why below line ok ? ask java compiler. s -= 2; s = (short)(s - 2); 

Java report error while c/c++ do not even display a warning message

in fact, c++ do the same things like Java do:
Automatic promotion of shot to int, but implicit the conversion.

Comments

Popular posts from this blog

react-native run-android : sun.security.provider.cert path.SunCertPathBuilderException : unable to find valid certification path to req uested target

react-native run-android : do not build/update modified code(App.js)

How to fix error : no module named sendgrid when try to use sendgrid python lib in PHP.