關(guān)于調(diào)用Map中Value的id和name問題!
為什么students.get(ID).name不能寫成st.name呢?會(huì)報(bào)錯(cuò)。System.out.println("成功添加第"+(i+1)+"名學(xué)生:" + st.id+"、"+st.name);
為什么students.get(ID).name不能寫成st.name呢?會(huì)報(bào)錯(cuò)。System.out.println("成功添加第"+(i+1)+"名學(xué)生:" + st.id+"、"+st.name);
2015-12-30
舉報(bào)
2015-12-30
if(str==null)已經(jīng)限定了str是null才能執(zhí)行這段代碼,你再用str.id顯然就是nullpointerexception了啊
你可以用newStudent.id
2015-12-30
o 突然明白了,因?yàn)楫?dāng)前是包含在if語句中的,此時(shí)st==null,所以此處不能使用st.id。