Java implicit “this” parameter in method?

拟墨画扇 提交于 2019-11-30 05:40:57

问题


Within the programming language Java do method invocations on an object, work by implicitly passing a reference to the object to act on and working as static methods?


回答1:


Details on how method invocation works can be found in the Java SE 7 JVM specification, section 3.7. For an instance method the this reference is passed as the first parameter. This reference is also used to select which method to invoke, since it might be overridden in a subclass, so it is a bit more complicated than a static method.




回答2:


In short, no. That is how C++ was originally written, back when it was just a system of macros, but that was only because nothing existed (in C) like classes or static functions.

Java simply calls methods on objects. It has a shared piece of code that is the method, so in that sense it's static conceptually, but there is a bit that tells the modifiers of a method, and static is one of the bits, and it is not set for normal methods.



来源:https://stackoverflow.com/questions/5738288/java-implicit-this-parameter-in-method

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!