简体   繁体   English

静态方法可以在Java中调用自身吗?

[英]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 ? 我有一个静态方法,删除一个ftp树,所以它需要递归调用自己,如果它找到一个子目录,它会引起混乱,因为它是静态的吗?

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. 编辑:我没有在我的帖子之前测试,因为如果它导致问题,我可能删除了我的测试目标之外的额外文件,不想冒风险。

不,它不会,静态方法可以用于递归调用。

nope. 不。 you're good. 你很厉害。 I apparently have to write at least 30 chars for this post to be accepted. 我显然必须为这篇文章写至少30个字符才能被接受。

no. 没有。 why would there be a problem? 为什么会出现问题?

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. 如果情况确实如此,你会很快发现 - 当堆栈框架堆叠在一起时,你会得到一个OutOfMemoryError。

不,它不会:)我没有看到任何理由比使用实例方法更多的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM