I am surprised to see that getters of height and width members has return type double, albeit they are int. Moreover, setSize method with double parameters has the following definition:
/**
 * 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);
}
Please have a look at Dimension class. Above comment says values cannot go beyond Integer.MAX_VALUE. Why?
Why do we have double in between? Is there any subtle reason? Can anyone please explain this to me? Sorry for my insistence!
java.awt.Dimension was retrofitted to fit into the java.awt.geom package, so that it can be used wherever a Dimension2D is required. The interface for the later deals with floating point, so Dimension has to also. Being limited to int fields, only a subset of doubles can be represented. Dimension2D.Float is similarly restricted.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With