看到height
和width
成员的getter方法返回类型是double
,虽然它们是int
,我感到非常惊讶。此外,接受double
参数的setSize
方法具有以下定义:
/**
* Sets the size of this <code>Dimension</code> object to
* the specified width and height in double precision.
* Note that if <code>width</code> or <code>height</code>
* are larger than <code>Integer.MAX_VALUE</code>, they will
* be reset to <code>Integer.MAX_VALUE</code>.
*
* @param width the new width for the <code>Dimension</code> object
* @param height the new height for the <code>Dimension</code> object
*/
public void setSize(double width, double height) {
this.width = (int) Math.ceil(width);
this.height = (int) Math.ceil(height);
}
请查看Dimension类。上面的评论说值不能超过Integer.MAX_VALUE。为什么?
为什么我们需要在中间使用double
?是否有任何微妙的原因?请问有人能解释一下吗?对于我的坚持表示抱歉!
double
的getter方法?有什么用处吗? - Ahameddouble
类型具有整数值会提高精度。我的意思是,double
类型的1517.00等于1517,所以一定有某些原因吧? - Ahamed