失去精度有在Java中過去的試卷一個問題,我的兄弟:將通過我們的隱式轉換
有了原始數據類型的隱式轉換,你可能會失去精度,並得到不正確的結果。
一個真實的,B假
的關鍵答案是:真正的
我認爲這既不會丟失精度也得到不正確的結果。我知道顯式轉換可能會失去精度並得到不正確的結果,但不是隱含的結果。
例如:
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.
作爲對筆記狀態:
隱式類型轉換:程序員不作任何嘗試轉換的類型,而所述類型自動地被轉換系統在某些情況下。
任何人都可以請指教?
非常感謝。
理查德所以你的意思是隱式轉換不會失去精度吧?答案是B,錯誤的權利? – bean
隱式轉換是指編譯器通過放入隱式轉換來接受代碼。如果存在編譯錯誤,則不存在轉換。 –