Re: HashMap get/put
Peter Duniho wrote:
Mike Schilling wrote:
[...]
The called class might haver changed at run-time; such a change
doesn't require that the caller be recompiled.
That seems like a serious versioning problem.
<Shrug.> If you want the freedom of run-time binding, you've
got to accept the consequences.
What happens if you have
a class where the method is changed from non-final to final? Does code
compiled with that class previous still get to override the now-final
method?
No, of course not. Similarly, if class A uses a public method
of class B, and then a new class B changes the method to private,
the already-compiled A can no longer use B's method.
I suppose that's one argument in favor of making all methods use virtual
dispatch, final or not. Then the method call always works the same
regardless. But it does seem to mean that if the contract for the class
changes, older code may wind up violating the new contract.
Yes, although it's not at all clear which party "violates" a
contract that's amended unilaterally.
The compiler will make sure that everything is kosher at the
time of compilation, but it cannot predict the future. The JVM,
looking at the actual .class files presented to it, is the final
arbiter of whether they'll play together or not.
--
Eric Sosman
esosman@ieee-dot-org.invalid