public Class A {
public static String s = "s";
public static int i = 0;
public int j = 1;
public static String getStaticString() {
int k = 2;
return s;
}
public String getString() {
int l = 3;
return "something";
}
}
根据很多资料,static variables
是存在heap
中的Perm
代,primitive
类型存在stack
中。
问题:
1、s
是存在heap
中的Perm
代,i
, j
, k
, l
存在哪呢?
2、static
方法存在哪?非static
方法存在哪?也就是说,getStaticString
存在哪,getString
方法存在哪?
j存在A的实例中,A的实例存在heap。
k, l都是在栈上(方法体中)创建的primitive,所以存在stack。