Java 隐式“this”方法中的参数?
在编程语言 Java 中,对对象进行方法调用,通过隐式传递对要操作的对象的引用来工作并作为静态方法工作?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有关方法调用如何工作的详细信息,请参阅 Java SE 7 JVM 规范,第 3.7 节。对于实例方法,
this
引用作为第一个参数传递。该引用还用于选择要调用的方法,因为它可能在子类中被重写,因此它比静态方法稍微复杂一些。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.简而言之,不。这就是 C++ 最初的编写方式,当时它只是一个宏系统,但这只是因为(在 C 中)不存在类或静态函数之类的东西。
Java 只是调用对象的方法。它有一段共享的代码,即方法,因此从这个意义上来说,它在概念上是静态的,但有一点告诉方法的修饰符,而 static 是其中之一,并且没有为普通方法设置它。
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.