class SomeClass<E> {
Map<String, String> someMethod();
}
And usage
SomeClass a = new SomeClass();
a.someMethod().get("foo") // returns object, not string!
//This code would not even compile
String s = a.someMethod().get("foo");
But if I remove generalization (<E>) from SomeClass -- it works.
It also works if I extract this method to interface and use interface in declaration:
interface Foo {
Map<String, String> someMethod();
}
class SomeClass implements Foo {
//.....
}
Foo foo = new SomeClass();
String s = foo.someMethod().getString("A");//it works
Why it happens? Where can I read about it? What is the best work-around? Thanks.