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 int
s 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.
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.
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