Created
September 23, 2017 08:42
-
-
Save kabutz/f971ef61f0eb784dc2376ad4f3ad7ea5 to your computer and use it in GitHub Desktop.
Three cheers (or more) for Java 9 release!
This file contains hidden or 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
// Compile and run in Java 9. Then compile and run in Java 8 and 9. Enjoy your new JDK :-D | |
public class Java9AtLast { | |
public static void hiphip(int cheers) { | |
try { | |
hiphip(cheers + 1); | |
} catch(StackOverflowError er) { | |
System.out.println("hooray x " + cheers); | |
} | |
} | |
public static void main(String... args) { | |
hiphip(0); | |
} | |
} |
You can produce some marvelous hacks with StackOverflowError - for example, make threads die without releasing their locks ... :-)
Fortunately synchronized is fairly robust in this way ...
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For java 8 the output is not what I've expected... It is able to catch an error (thanks for the learning experience 👍 )!
For java 9 you'd better don't try to catch the error (it becomes some cryptic):
When removing the try-catch, it is more comprehensible: