FileInputStream fis;
if(true) fis = new FileInputStream("d:\\test.txt");
fis.xxx//使用就会编译错误
只要存在if这种编译器不能确定fis一定被赋值了的在使用时会编译出错
层次分明:
FileInputStream fis = null; //在栈中声明对象
fis = new FileInputStream("d:\\test.txt");//在堆中实例化对象
FileInputStream fis;
if(true) fis = new FileInputStream("d:\\test.txt");
fis.xxx//使用就会编译错误
只要存在if这种编译器不能确定fis一定被赋值了的在使用时会编译出错
层次分明:
FileInputStream fis = null; //在栈中声明对象
fis = new FileInputStream("d:\\test.txt");//在堆中实例化对象