Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rectangle class functions getX(), getY(), etc. return in double precision

Well I know they do, according to my experience and the Oracle Java API documentation, but I wonder why. Through the constructor I'm only allowed to pass int type arguments to the Rectangle class, the internal data representation of x, y, etc. are of the type int and also setSize() only excepts arguments of the type int. But why do all methods like getX(), getY(), getWidth(), etc. return a double when there can not be any precision? Why not simple ints as expected?

EDIT: I do understand that it is derived from the Rectangle2D class, but that is still no reason to just simply not provide any int-based getX() and getY() functions, as in difference with the Point and Point2D class those methods are not abstract. Also setLocation() is not abstract either.

like image 408
Jori Avatar asked Jul 01 '13 09:07

Jori


1 Answers

I believe because it extends Rectangle2D which is used in Graphics2D, and it says :

This class is only the abstract superclass for all objects that store a 2D rectangle. The actual storage representation of the coordinates is left to the subclass.

So if any of its subclass represents the dimensions in double should be compatible with one another, perhaps. If you read the Javadoc for Rectangle#getX():

Returns the X coordinate of the bounding Rectangle in double precision.

Specified by:

public abstract double getX() in class RectangularShape.

like image 90
AllTooSir Avatar answered Nov 09 '22 11:11

AllTooSir