I have a code piece that looks something like what I've pasted below:
import java.util.LinkedHashMap;
import java.util.Map;
public class GenericMagic {
GenericMagic() {
}
private class Container {
int doSomething(){ return 42;}
@Override
public String toString() {
return "Container"+doSomething();
}
}
private class TheCache<String, Container> extends LinkedHashMap<String, Container> {
@Override
protected boolean removeEldestEntry(Map.Entry<String, Container> eldest) {
Container value = eldest.getValue();
value.doSomething();//if I comment this out it compiles
System.out.println(value);
return false;
}
}
}
In my 'TheCache' class, I want to constrain the generic type to a specific, which is fine, but when I get the 'value' as a Container, it is somehow not typed, in that I cannot execute the doSomething method. Why?