为什么我在Java中遇到stackoverflow?

为什么我在Java中遇到stackoverflow?,java,recursion,stack-overflow,Java,Recursion,Stack Overflow,我有一个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; }

我有一个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;
    }

而不是
返回通配符(x,y,子字符串,count++)
try
返回通配符(x,y,子字符串,++count)

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

您可能还需要更新
返回通配符(x.substring(substring),y,substring++,count)出于同样的原因


另外,您的最后一个
if
语句被破坏了……我认为
系统.out
返回false
想要在
if
块之外,而不是
返回通配符(x,y,子字符串,count++)
try
返回通配符(x,y,子字符串,++count)

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

您可能还需要更新
返回通配符(x.substring(substring),y,substring++,count)出于同样的原因


还有,你最后的
if
语句被破坏了……我认为
系统.out
return false
想要在
if
块之外

你怎么知道
if
语句被忽略了?因为如果它没有被忽略,递归就会结束。有人能解释我为什么会遇到堆栈溢出吗因为您有一个需要帮助回答的编程问题。如果忽略了
语句,您如何知道
呢?因为如果不忽略它,递归将结束。有人能解释我遇到stackoverflow的原因吗因为你有一个编程问题需要帮助回答。