I want to check if a variable is initialized before using it.
java.io.File yDriveFolder;
//move files to temp folder
for(int i=0; i<filesForDocument.length; i++){
...
yDriveFolder = new java.io.File(yDrivePath + "/");
...
}
//delete source folder when it is done
if(filesForDocument.length> 1){
if(yDriveFolder != null){
yDriveFolder.delete();
}
}
error: variable yDriveFolder might not have been initialized
How should I check if a variable is initialized before using it?
>Solution :
Write something like java.io.File yDriveFolder = null; Then the compiler knows you know it is not initialized.