为了减小内存占用,为什么有些 JavaFX 几何方法不是静态的?

huangapple 未分类评论44阅读模式
英文:

Why are some JavaFX geometry methods not static for a smaller memory footprint?

问题

我刚开始接触JavaFX,但实际上并不太理解为什么某些方法不是静态的。

举例来说,Point2D类有一些实例方法,比如distance(Point2D)angle(Point2D)等等。

从性能的角度来看,这是否合理呢?

我可能是错的,但是如果我创建了比如说1000个Point2D类的对象,这些实例方法在内存中会有1000份拷贝。

如果有一个静态方法,像是Point2D.distance(Point2D p1, Point2D p2),它在内存中只有一份拷贝。

有人可以解释一下为什么会是这样吗?

谢谢。

英文:

I am just getting into JavaFX but don't really understand why some methods are not static.

For example, the Point2D class has a few instance methods, such as distance(Point2D), angle(Point2D), and so on.

Is it logical performance-wise?

I might be wrong, but if I create let's say 1000 objects of the Point2D class, there would be 1000 copies in the memory of these instance methods.

If there was one static method, like Point2D.distance(Point2D p1,Point2D p2), it would have one copy in the memory.

Can someone explain why is it this way?

Thanks

huangapple
  • 本文由 发表于 2020年7月24日 14:59:20
  • 转载请务必保留本文链接:https://java.coder-hub.com/63068432.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定