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?
It looks like you’ve forgotten to return a
List<String>for theelsebranch.