Double
is a wrapper class on top of the primitive double
. It can be cast to double
, but it cannot be cast to int
directly.
If you use double
instead of Double
, it will compile:
double d = 10.9;
int i = (int)(d);
You can also add a cast to double
in the middle, like this:
int i = (int)((double)d);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…