Java过去的试卷中有一个问题是我的兄弟:
使用原始数据类型的隐式转换,您可能会丢失精度并获得不正确的结果。
A 真,B 假
答案的关键是 A:是的
我认为它既不会失去精度也不会得到不正确的结果。我知道显式转换可能会失去精度并得到不正确的结果,但不是隐式转换。
例如:
int i = 9;
short s = 3;
i = s; // implicit conversion, neither loose
//precision nor incorrect results
s = i; // compile error, do we call this implicit conversion?
//if yes, then the answer to question 3 is True,
//but I don't think this is an implicit conversion,
//so I think answer is false.
如注释所述:
隐式类型转换:程序员不尝试转换类型,而是在某些情况下由系统自动转换类型。
有人可以建议吗?
非常感谢。