Created
July 26, 2012 16:58
-
-
Save lukecampbell/3183219 to your computer and use it in GitHub Desktop.
Example of Java's short circuitness
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(work)Lukes-ASA-Macbook:tmp luke$ javac ShortCircuit.java | |
(work)Lukes-ASA-Macbook:tmp luke$ java ShortCircuit | |
Mind Blown |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ShortCircuit | |
{ | |
public static boolean do_something() | |
{ | |
System.out.println("You shouldn't see this."); | |
return true; | |
} | |
public static void main(String[] args) | |
{ | |
if(false && do_something()) | |
{ | |
System.out.println("You really shouldn't see this."); | |
} | |
System.out.println("Mind Blown\n"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment