为什么我在Java中遇到stackoverflow?

use*_*517 1 java stack-overflow recursion

我有一个int,"count"在每次递归后添加一个,但我也有一个if语句,一旦int等于或大于另一个整数就停止递归.不知何故if语句被忽略了.

public static boolean wildcard(String x, String y, int substring, int count) {
    if (count >= y.length()){
        System.out.println("asdf");
        return true;
    }

    if (x.charAt(count) == y.charAt(count)){
        System.out.println("ALSKDFJKL");
        return wildcard(x, y, substring, count++);
    }
    if (y.charAt(count) == '*'){
        return wildcard(x.substring(substring), y, substring++, count);


    System.out.println("wildcard end");
    return false;
    }
Run Code Online (Sandbox Code Playgroud)

Mad*_*mer 5

而不是return wildcard(x, y, substring, count++);尝试return wildcard(x, y, substring, ++count);

count++ 是一个后增量(意味着它将在方法返回后递增)

您可能还想以return wildcard(x.substring(substring), y, substring++, count);同样的原因更新.

此外,你的最后一个if陈述被打破......我认为System.out并且return false想要超出if障碍