昨天下午和一個同事討論這個問題的。一向討論會有結果,昨天居然沒有結果。
晚上和群里面兄弟又討論了,沒有結果。貼出來,等我以后長進了,也好看看,自己當初是多么地菜。
當然,最重要的就是和blog讀者分享了。
public class Test {
static int x;
static {
int x = 0;
}
{
int x = 0;
}
public static void main(String[] args) {
int x = 0;
while (true) {
// 編譯錯誤
// Doplicate local valiable x
int x = 0;
}
}
}
static不是只在data segment上分配內存嗎?如果是的話,static代碼塊里的int x=0;是如何分配的.。。。。。。。。。
很暈。求高手指教。