开发者

What do you mean by the caller of a method in Java?

I am confused about what a caller of a method menans in Java. Can someo开发者_C百科ne clarify that with an example?


It is referring to the method that is calling the other method.

public void foo() {
  bar();
}

public void bar() {
   // foo could be the caller of bar here.
}

In general, if you look in your stacktrace, each two consecutive lines A and B basically mean »A is called by B« or »B is the caller of A«.


See the following example:

public static void main(String[] args) {
    System.out.println("hello, world");
}

Method main() is the caller of println()


Some code is calling the method. That would be the caller.

Example:

public class A {
   public static void main(String[] argv) {
       System.out.println("Hello");
   }
}

Here, the method println is called by A#main (method main in class A).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜