(note: Double example)
When initializing Double, a value of Double or double is required as:
Double a = 0; //does not compile
if you do not press twice, or add 'd'
Double b = (double)0;
Double c = 0d;
When it becomes confusing, it ...
It compiles, although its value becomes 0 (int)
Double d = true ? 0 : 0d;
How does it
Double e = false ? 0 : 0d;
But they will not compile:
Double f = false ? 0 : 0; //cannot convert from int to Double
Double g = true ? 0 : 0; //cannot convert from int to Double
Why is this given an error for f and g, but not for d
ps. Using Java8 (don't expect the difference, but updates are happening)
source
share