Java - 方法调用和方法执行
方法的调用和执行有什么区别?两个是同一个东西吗?
What is the difference between the invocation and execution of a method ? Are two the same thing ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我不认为这些是标准术语。不过我对它们的理解如下:
I don't think these are standard terms. However I understand them the following way:
好吧,调用一个方法意味着通过它的名称和参数来调用它;执行一个方法意味着执行它..运行它,一行一行地获取它的行并运行它们。
Well, invoking a method means calling it by its name and parameters; executing a method means executing it.. running it, fetching its lines one by one and run them.
我不知道这些的任何标准定义,但我的理解是:
调用导致执行。
I'm not aware of any standard definitions of those, but my understanding is this:
Invocation results in execution.
有一些细微的差别:
另请参阅:远程方法调用概述。当您认为该方法是远程的时,调用(开始执行某项操作的请求)和执行(如果请求成功,则在某处发生的操作)之间的区别变得更加明显。
还要考虑反思的情况。这是
java.lang.reflect.Method
:这里也明确了调用和执行是两个不同的东西。如果您需要更有说服力,请考虑此反射上下文中调用与执行
NullPointerException
的情况:obj == null
当方法是实例方法InitationTargetException
的原因There are some subtle differences:
See also: Overview of Remote Method Invocation. When you consider the method to be remote, the difference between invocation (a request to start the execution of something) and execution (something that is happening somewhere if the request is successful) becomes more apparent.
Consider also the case with reflection. This is a method of
java.lang.reflect.Method
:Here also clearly invocation and execution are two different things. If you need more convincing, consider the case of an invocation vs execution
NullPointerException
in this reflection context:obj == null
when the method is an instance methodInvocationTargetException
据我所知:
调用是执行的前置步骤。如果调用成功,则开始执行过程...
例如,
参数(方法签名中声明的变量)仅在方法调用期间才会创建。它是执行的前置步骤。
调用之后,将执行实际的方法,即在方法执行过程中将创建局部变量(在方法体中声明的变量)。
所以参数在调用,局部变量在执行……
这样,调用成功就会继续执行。
As far as my knowledge is concern:
Invocation is the pre-step for execution. If invocation is successful then the process of execution starts...
For example,
Parameters (the variables declared in the method signature) will be created only during method invocation.It is the pre-step for execution.
After the invocation, the actual method will be executed i.e., the local variables(the variables which are declared in the method body) will be created during the method execution.
so parameters are at invocating and local variables are at executing...
Thus, The successful invocation leads to proceed to execution.