英文:
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
专注分享java语言的经验与见解,让所有开发者获益!
评论