Java "add return statement" error

1k views Asked by At
public class1 foo ( class1 t)
{
    if ( object == null ) return t;
    else foo(t.childObject);
}

Java keeps telling me that there is no return statement. I can understand what is wrong here, but I cannot fix it without removing the recursion, which I really need. Is there any way to bypass this error?

1

There are 1 answers

1
Bill the Lizard On BEST ANSWER

You need a return in the else case.

public class1 foo ( class1 t)
{
    if ( object == null ) return t;
    else return foo(t.childObject);
}