Class Generics break completely seperate method
- by TheLQ
I found a strange problem when I used class Generics Today: Setting some broke a completely separate method.
Here's a small example class that illustrates the problem. This code works just fine
public class Sandbox {
public interface ListenerManagerTest {
public Set<Listener> getListeners();
}
public void setListenerManager(ListenerManagerTest listenerManager) {
for (Listener curListener : listenerManager.getListeners())
return;
}
}
Now as soon as I use class Generics, the getListeners() method returns Set<Object> instead of Set<Listener>
public class Sandbox {
public interface ListenerManagerTest<E extends Object> {
public Set<Listener> getListeners();
}
public void setListenerManager(ListenerManagerTest listenerManager) {
for (Listener curListener : listenerManager.getListeners()) //Expected Listener, not Object
return;
}
}
What would cause this error? The ##java channel on Freenode said it was because of compile time candy and that I was using a raw type. But how would an raw class type break all generics in the class? And how would of worked before?