Java Point,getX()和point.x之间的区别 [英] Java Point, difference between getX() and point.x
问题描述
我很困惑为什么Java Point类接受两个int参数并且getX()和getY()方法返回双精度。
例如我可以定义一个点
I am confused to as why the Java Point class takes in two int paramaters and the getX() and getY() methods return doubles. For example I could define a Point
Point p = new Point(4,6);
如果我打电话..
p.getX();
它将返回4.0。如果我打电话
It would return 4.0. and if I were to call
p.x;
我会得到4。
任何原因是什么?
推荐答案
Point2D.Double
和 Point2D.Float
扩展 Point2D
的类,它是 Point
的超类并且他们需要能够使用浮点值。请注意,还有 setLocation(double,double)
。
There are Point2D.Double
and Point2D.Float
classes that extend Point2D
which is a superclass of Point
and they need to be able to work with floating point values. Note that there is also a setLocation( double, double )
.
Point2D
是一个抽象类,用于实现点的距离计算, setLocation
, getX
和 getY
是它的抽象方法,这就是为什么它们都使用双打
以及为什么 Point
必须在签名中使用 double
来实现它们。
Point2D
is an abstract class that implements the distance calculation for points, and setLocation
, getX
, and getY
are its abstract methods, which is why they all use doubles
and why Point
has to implement them with double
s in the signature.
这篇关于Java Point,getX()和point.x之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!