No, Java will not implicitly narrow a primitive value. You cannot cast from a double to byte because the byte has a range smaller than the double and it does not contain decimals like a double does. You can explicitly cast it to a Byte via a boxing conversion. This guards against accidental loss of precision.
1 comment:
No, Java will not implicitly narrow a primitive value. You cannot cast from a double to byte because the byte has a range smaller than the double and it does not contain decimals like a double does. You can explicitly cast it to a Byte via a boxing conversion. This guards against accidental loss of precision.
More..Interview Questions
Post a Comment