Java Point,getX() 和 point.x 的区别
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10221327/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Java Point, difference between getX() and point.x
提问by James Fazio
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
我很困惑,为什么 Java Point 类接受两个 int 参数,而 getX() 和 getY() 方法返回双精度值。例如我可以定义一个 Point
Point p = new Point(4,6);
If I were to call..
如果我打电话..
p.getX();
It would return 4.0. and if I were to call
它将返回 4.0。如果我打电话
p.x;
I would get 4.
我会得到 4。
Any reason for this?
这有什么原因吗?
采纳答案by trutheality
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.Double
和Point2D.Float
扩展类Point2D
是一个超类Point
,他们需要能够将工作与浮点值。请注意,还有一个setLocation( double, 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.
Point2D
是一个抽象类,它实现的距离计算点,和setLocation
,getX
和getY
是它的抽象方法,这就是为什么他们都用doubles
,为什么Point
有执行这些double
S IN的签名。