I want to write a code like this
public int recursiveMethod() {
for (int i = 0; i < 10; i++) {
if (someBool) {
return recursiveMethod();
} else {
return -1;
}
}
}
but this gives compile error missing return statement. Is there other way I can achieve this.
UPDATE : actual code
public static File searchFile(File currentFile) {
File[] results = null;
if (currentFile.isDirectory()) {
for (File file : currentFile.listFiles()) {
if (file.isDirectory()) {
return searchFile(file);
} else {
results = file.getParentFile().listFiles(new FilenameFilter() {
public boolean accept(File dir, String name) {
return name.toLowerCase().endsWith(".sh");
}
});
if (results.length > 0) {
return results[0];
} else {
return null;
}
}
}
} else {
results = currentFile.getParentFile().listFiles(new FilenameFilter() {
public boolean accept(File dir, String name) {
return name.toLowerCase().endsWith(".sh");
}
});
if (results.length > 0) {
return results[0];
} else {
return null;
}
}
}