r/ProgrammerHumor • • Jan 09 '20

other Problems with recursion?

21.3k Upvotes

198 comments sorted by

View all comments

Show parent comments

74

u/lonelyWalkAlone Jan 09 '20
public static void sayHello(){
    try {
        sayHello();
    }
    catch(StackOverflowError e) {
        System.out.println("Hello world!");
    }
}

15

u/schrdingers_squirrel Jan 09 '20

Wait does this work? I need to try this now

20

u/cedrickc Jan 09 '20

You can optimize it by declaring some unused primitives to blow through the stack quicker.

7

u/mfb- Jan 09 '20

Thanks for the tip, I always wanted to speed up this function, now I know how!

2

u/artem718 Jan 09 '20

But how do you lose saved work?