javaandroidreturn

What is the use of return statement in a void function


What does return; mean? Is it like break?

public void run() {
    if(imageViewReused(photoToLoad))
        return;
    Bitmap bmp=getBitmap(photoToLoad.url);
    memoryCache.put(photoToLoad.url, bmp);
    if(imageViewReused(photoToLoad))
        return;
    BitmapDisplayer bd=new BitmapDisplayer(bmp, photoToLoad);
    Activity a=(Activity)photoToLoad.imageView.getContext();
    a.runOnUiThread(bd);
}

If the second imageViewReused(photoToLoad) returns true, BitmapDisplayer bd=new BitmapDisplayer(bmp, photoToLoad) won't be executed, right?


Solution

  • Return statement skips the remaining execution of a function scope.

    Worth reading:

    1. return : http://docs.oracle.com/javase/tutorial/java/javaOO/returnvalue.html
    2. break : http://docs.oracle.com/javase/tutorial/java/nutsandbolts/branch.html