Covariance in Java

Posted by Bobby on Stack Overflow See other posts from Stack Overflow or by Bobby
Published on 2010-06-16T04:51:27Z Indexed on 2010/06/16 5:12 UTC
Read the original article Hit count: 462

Filed under:
|

Why does the following not work in Java? It would work in C#:

public static final List<String> Split(String str, char delimiter)
    {
        if ((str == null) || "".equals(str))
        {
            return new CopyOnWriteArrayList<String>();
        }
    }

I get an error saying this method has to return List. CopyOnWriteArrayList implements the List interface. Why does covariance not apply on return values in Java?

© Stack Overflow or respective owner

Related posts about java

Related posts about covariance