Let's say I have this base class:
abstract public class Base {
abstract public Map save();
abstract public void load(Map data);
}
to my surprise I could do this in a derived class:
public class Derived extends Base {
@Override
public Map<String, String> save() { //Works
...
}
...
}
but I couldn't do this:
public class Derived extends Base {
@Override
public void load(Map<String, String> data) { // Fails
...
}
...
}
What is happening here? Why can I use a specialized return type but not a specialized parameter type?
What's even more confusing is that if I keep the original declaration of load
, I can just assign it to the more special type:
public class Derived extends Base {
@Override
public void load(Map data) {
Map<String, String> myData = data; // Works without further casting
...
}
...
}