0

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.

Community
  • 1
  • 1
Chiseled
  • 2,280
  • 8
  • 33
  • 59
  • 1
    The main difference is the way they are dispatched: instance methods may require a further indirection to be called. That is, unless the JIT compiler can establish that the method definitely isn't overridden, in which case it can choose to dispatch instance methods directly and, after a time, even inline the method call completely. This kind of aggressive optimisation is the main reason the internal representation of methods isn't prescribed exactly. – biziclop Aug 03 '15 at 21:10

1 Answers1

4

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!

templatetypedef
  • 362,284
  • 104
  • 897
  • 1,065