As you can see in the Oracle Documentation for java.awt.Point, x and y are stored as int
. However, getX
and getY
return double
. While there is a setLocation
method that takes 2 double
types, there is no constructor that does. Furthermore, the double
gets truncated to an int
internally anyway.
Is there a good reason for this? You might avoid a cast on setLocation
by having a method that takes double
types, but you have the opposite problem when you call getX
and getY
. There's also a misrepresentation of the precision of the Point class by returning a double
from getX
and getY
.
Because it extends from java.awt.geom.Point2D which is used in Graphics2D abstract class. It was implemented this way for compatibility reason since before this, java only supported java.awt.Graphics where all methods are int based.
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