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.

[1266 byte] By [zanfolima] at [2007-11-27 2:11:55]
# 1
Sounds like the "other project" is not using Java5 or your class gets compiled with source compatibility of 1.4 before putting it into the jar.
stefan.schulza at 2007-7-12 2:05:39 > top of Java-index,Core,Core APIs...