Invocation of java generic method

Viewed 468

Given the generic method:

<T> List<T> getGenericList(int i) {...}

the following code compiles without any warning:

public List<String> getStringList(boolean b){
    if(b)
        return getGenericList(0);
    else
        return getGenericList(1);
}

but this one generates 'Type mismatch' compilation error:

public List<String> getStringList(boolean b) {
    return (b) ? getGenericList(0) : getGenericList(1);
}

Why?

5 Answers
Related