Alkiviadis95
Alkiviadis95

Reputation: 41

Java "add return statement" error

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?

Upvotes: 1

Views: 1036

Answers (1)

Bill the Lizard
Bill the Lizard

Reputation: 405765

You need a return in the else case.

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

Upvotes: 7

Related Questions