StackOverflowError whenever I initialise a constructor with a recursive method

35 Views Asked by At

Whenever I initialize the WinConditons class and insert a recusive function into the parameters it I end up getting a StackOverFlowError, this doesn't happen if I don't insert the recursive function into WinCons parameters

I've tried applying the recursive method(TriGlobalHandComb) into another 2d list but I get the same issue regardless

public class TexasHoldem {
 public TexasHoldem(){
        List<String> testCurrentGlobalHand  = Arrays.asList("14s", "4h", "7s", "10c", "6s");
       String[] personalHand = {"2d", "4s"};
       List<List<String>> tempComb = TriGlobalHandComb(testCurrentGlobalHand, new ArrayList<>());
       WinConditions winCons = new WinConditions(tempComb, personalHand);
    }
    public List<List<String>> TriGlobalHandComb(List<String> globalHand, List<String> comb) {
        ArrayList<String> source = new ArrayList<>(globalHand);

        if (comb.size() == 3) {
            List<List<String>> result = new ArrayList<>();
            result.add(comb);
            return result;
        }
        List<List<String>> result = new ArrayList<>();
        Iterator<String> iterator = source.iterator();
        while (iterator.hasNext()) {
            String item = iterator.next();
            iterator.remove();

            List<String> newComb = new ArrayList<>(comb);
            newComb.add(item);

            result.addAll(TriGlobalHandComb(new ArrayList<>(source), newComb));
        }
        return result;
    }
}

public class WinConditions extends TexasHoldem{
    List<List<String>> currentGlobalHandComb;
    String[] personalHand;
    WinConditions(List<List<String>> currentGlobalHandComb, String[] personalHand){
        this.currentGlobalHandComb = currentGlobalHandComb;
        this.personalHand = personalHand;
    }
}
0

There are 0 best solutions below