Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can a static method call itself in Java?

I have a static method, that deletes a ftp tree, so it needs to call itself recursively if it finds a sub dir, would it cause confusion because it's static ?

Edit : I didn't test before my post because if it causes a problem, I might have deleted extra files outside my test target, didn't want to risk it.

like image 581
Frank Avatar asked Feb 13 '11 22:02

Frank


4 Answers

No, it wouldn't, static methods can be used in recursive calls.

like image 180
Femaref Avatar answered Sep 18 '22 12:09

Femaref


nope. you're good. I apparently have to write at least 30 chars for this post to be accepted.

like image 21
selbie Avatar answered Sep 22 '22 12:09

selbie


no. why would there be a problem?

like image 44
pstanton Avatar answered Sep 20 '22 12:09

pstanton


It'll only be a problem if your recursive method doesn't have a good stopping condition. You'll find out quickly if that's the case - you'll get an OutOfMemoryError when the stack frames pile up on top of each other.

like image 25
duffymo Avatar answered Sep 19 '22 12:09

duffymo