Override mechanics - unintentionally overriding newer implementations
Ali Lahijani
alahijani at gmail.com
Thu Nov 29 00:36:27 PST 2012
Note that @Override is currently @Retention(SOURCE), so there is nothing in
the class file that specifies overriding was intended. Even if this
RetentionPolicy is changed, or a new class-file flag which means the same
is added, all implementations of an interface will need to be recompiled,
otherwise they won't work.
There is also the bigger issue of source compatibility: a
class implementing java.util.List written before JDK 5 does not have
@Override annotations in its source, so even if it is recompiled it will be
rejected. You need to add @Override annotations to make it compile.
A more moderate option would be to annotate new methods with an
@ExplicitOverride. Old methods without @ExplicitOverride will
be overridden with the current semantics. (Or maybe there should be an
opt-out syntax rather than an opt-in.)
Anyway, I think it's a big change so the semantics of the JVM, which
usually means that it won't be considered for the JDK 8 time-frame.
More information about the lambda-spec-observers
mailing list