Requirement: method1 should accept object of any type such as Map<String,User>, Map<String,Employee>, Map<String,Account> etc.
Scenario1:
method1(Map<String,Object> map)
{
method2(map); //signature -> method2(Map<String,Object> map){//code here}
}
Problem: method1 is accepting only argument of type Map<String,Object>. However, there is no problem in passing argument from method1 to method2
Scenario2:
method1(Map<String,? extends Object> map)
{
method2(map); //signature -> method2(Map<String,Object> map){//code here}
}
Now, method1 is accepting argument of any type Map<String,Object>, Map<String, User>. However, there is a problem in passing argument from method1 to method2
Problem: compile time exception when passing argument from method1 to method2. exception: required type Map<String, Object>, provided: Map<String, capture of ? extends Object>
I have control over method1, I can change the signature. But, it needs to meet above requirement. I don't have control over method2. I must pass argument of type Map<String, Object>.
Solution: `method2((Map<String, Object>) map)
Earlier, there was a mistake in typecasting. Now code is working fine. Thanks for responses.