currenty I'm facing a problem with generic classes in Java.
I have something like this:
public class GenericClass<T> {
T doSomething() {...}
Collection<String> getCollection() {...}
}
Now I instantiate an object of that class without the type parameter, since I'm not intereseted in that or I don't know it.
GenericClass obj = new GenericClass();
for (String str : obj.getCollection() { // won't work
...
}
The problem is, that the compiler does not simply throw away the information about the type-parameter, but also about the type of the Collection (String), although that's independent from the parameter.
Am I doing something wrong, or is that a restriction of Java? If so, why is that a restriction?