gpt4 book ai didi

java - 矩形类函数 getX()、getY() 等以 double 返回

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:32:35 27 4
gpt4 key购买 nike

嗯,根据我的经验和 Oracle Java API 文档,我知道他们这样做,但我想知道为什么。通过构造函数,我只允许将 int 类型的参数传递给 Rectangle 类,x、y 等的内部数据表示是 类型intsetSize() 仅排除 int 类型的参数。但是,为什么所有方法,如 getX()getY()getWidth() 等,在没有精确?为什么不像预期的那样简单 int

编辑:我知道它是从 Rectangle2D 类派生的,但是仍然没有理由不提供任何基于 intgetX()getY() 函数,与 PointPoint2D 类不同,这些方法不是抽象的。此外,setLocation() 也不是抽象的。

最佳答案

我相信因为它扩展了Rectangle2DGraphics2D 中使用,它说:

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.

因此,如果它的任何子类表示 double 中的维度,也许应该彼此兼容。如果您阅读 Rectangle#getX() 的 Javadoc :

Returns the X coordinate of the bounding Rectangle in double precision.

Specified by:

public abstract double getX() in class RectangularShape.

关于java - 矩形类函数 getX()、getY() 等以 double 返回,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17400840/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com