为什么java.awt.Point中提供了一些方法来设置和获取双打,但商店X和Y为int的? [英] Why does java.awt.Point provide methods to set and get doubles but store x and y as int's?

查看:228
本文介绍了为什么java.awt.Point中提供了一些方法来设置和获取双打,但商店X和Y为int的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你可以在 java.awt.Point中的 / A>,X和Y存储为 INT 的getX 的getY 收益双击。虽然是一个的setLocation 方法,它有2 双击类型,没有构造一样。此外,双击被截断为 INT 内部无妨。

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.

是否有一个很好的理由?你可能会避免在的setLocation 铸造由具有采取的方法双击的类型,但你必须当你相反的问题叫的getX 的getY 。还有Point类的precision的misre presentation通过返回双击的getX 的getY

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.

推荐答案

由于它java.awt.geom.Point2D中这是在Graphics2D的抽象类使用的延伸。因为在此之前有人以这种方式实现的兼容性原因,所有的方法都INT基于Java只支持java.awt.Graphics。

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.

这篇关于为什么java.awt.Point中提供了一些方法来设置和获取双打,但商店X和Y为int的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆