Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialShariq Shaikh
13,945 PointsShouldn't there be an else statement in the method definition of isExternalStorageAvailable()?
In the corresponding video Evan defines in FilesUtilities called isExternalStorageAvailable() with an if statement which returns true should the condition be meet. But after he close the if statement instead of then defining an else statement that would return false, he instead has the entire method return false:
public static boolean isExternalStorageAvailable(){ String state = Environment.getExternalStorageState(); if(Environment.MEDIA_MOUNTED.equals(state)){ return true; } return false; }
Would this not negate the if statement of this method?
Billy Ashmall
Courses Plus Student 6,610 PointsBilly Ashmall
Courses Plus Student 6,610 Pointsit does not need an else because if it does not go inside the if statement which produces a return true it will go to the next line which is return false. The return tells it to break out of the current code block and not run any further code in that block. When it gets back to the variable that calls isExternalStorageAvailable() the variable is set with either true, or false.