简体   繁体   English

静态方法和实例方法的内部内存表示形式之间的区别

[英]Difference between internal memory representation of static methods and instance methods

From other posts in this forum , It looks like only a copy of instance methods are stored in the memory , along with the class itself. 在该论坛的其他帖子中,似乎只有实例方法的副本与类本身一起存储在内存中。 All instances of this class share this single copy. 此类的所有实例共享此单个副本。

By definition , static methods belong to a class and only one copy of it is shared by all instances. 根据定义,静态方法属于一个类,并且所有实例仅共享它的一个副本。 So it makes sense to internally store static methods with the class. 因此,在类中内部存储静态方法是有意义的。

Would it be right to conclude that there is no difference between internal representation of static and instance methods. 得出结论,静态方法和实例方法的内部表示形式之间没有区别是正确的。

This is completely implementation-dependent, but generally speaking, there's no fundamental difference between the in-memory representation of static and nonstatic methods. 这完全依赖于实现,但是总的来说,静态方法和非静态方法的内存表示形式之间没有根本区别。 Internally, they're just executable (byte)code, which has the same representation regardless of whether the method has a receiver object. 在内部,它们只是可执行(字节)代码,具有相同的表示形式,无论该方法是否具有接收器对象。

Hope this helps! 希望这可以帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM