方法不管static与否,都在方法区。 按照java虚拟机规范第三版(Draft): The Java virtual machine has a method area that is shared among all Java virtual machine threads. The method area is analogous to the storage area for compiled code of a conventional language or analogous to the “text” segment in a UNIX® process. It stores per-class structures such as the runtime constant pool, field and method data, and the code for methods and constructors, including the special methods (§3.9) used in class and instance initialization and interface initialization.
举个例子, Integer i = new Integer(1000); System.out.println(i); 首先要去方法区找到System.out的类型信息java.io.PrintStream,然后通过类型信息找到println(Object)方法(方法信息和代码)。 然后加载参数i 最后调用方法println 调用方法就是在栈区建立该方法的运行栈,执行println的处理过程。(这个过程中使用i所指向的对象就会和堆产生关联了)
按照java虚拟机规范第三版(Draft):
The Java virtual machine has a method area that is shared among all Java virtual
machine threads. The method area is analogous to the storage area for compiled
code of a conventional language or analogous to the “text” segment in a UNIX®
process. It stores per-class structures such as the runtime constant pool, field and
method data, and the code for methods and constructors, including the special methods
(§3.9) used in class and instance initialization and interface initialization.
Integer i = new Integer(1000);
System.out.println(i);
首先要去方法区找到System.out的类型信息java.io.PrintStream,然后通过类型信息找到println(Object)方法(方法信息和代码)。
然后加载参数i
最后调用方法println
调用方法就是在栈区建立该方法的运行栈,执行println的处理过程。(这个过程中使用i所指向的对象就会和堆产生关联了)