Constantin
Constantin

Reputation: 1506

Why does java.awt.Point return a double for both getX() and getY() instead of int?

Both x and y are defined as int in class Point. Why then are the methods getX and getY returning double?

Thankfully x and y are exposed as public so we need not cast to int to get the values as such but curious why these methods do not return int.

Upvotes: 2

Views: 1524

Answers (2)

Les
Les

Reputation: 241

It inhereted from the java.awt.geom.Point2D wich contains abstract #getX.

public abstract double getX();

Why it was done by this way I'm wondering too. Maybe here is the answer:

@since 1.2

Upvotes: 1

Kayaman
Kayaman

Reputation: 73558

Because it inherits the Point2D class which defines them as returning double.

It also defines 2 inner classes which stores the values as floats and doubles, respectively.

Old classes can look weird after 20+ years.

Upvotes: 4

Related Questions