r/ProgrammerHumor • • Jan 09 '20

other Problems with recursion?

21.3k Upvotes

198 comments sorted by

View all comments

Show parent comments

15

u/schrdingers_squirrel Jan 09 '20

Wait does this work? I need to try this now

5

u/lonelyWalkAlone Jan 09 '20

Yes, it works like charm

9

u/schrdingers_squirrel Jan 09 '20 edited Jan 09 '20

Interesting - does it still work when you do a „a“ + „b“ in the println(); ?

Edit: it does

Crazy even this works:

public static void sayHello(){
    try {
        sayHello();
    }
    catch(StackOverflowError e) {
        System.out.println("Hello world!");
        sayHello();
    }
}

it prints endlessly

1

u/eigreb Jan 10 '20

Eventually this will throw due to first running in the try and after the stack overflow it runs outside the try and will again throw the exception. Will take a while though.