Generic return types in libraries
Just today I found something that I haven磘 realized yet about Java磗 generic implementation. It goes like this:
I have a utility class that happens to return a collection of strings, as:
publicclass MyUtilityClass{
public Collection<String> listNames(){
....
}
}
Note that the class itself is not parameterized. If I use this class in the same project in eclipse (that is, the client class has access to the source code of MyUtilityClass and they are compile thogether), I can assign the return o 'listNames' to a Collection<String> variable.
BUT, if I use this same class in another project - or make it available in a different jar - as a component, the return value is no longer of type Collection<String>, but just Collection....
This makes sense since the 'erasure' feature of generics, but it seems quite an important issue in the generic implemenation...
I am missing something here?
TIA,
Tedi
PS: I ended up returning a String[] from the method.

