Simulate @Override in JDK 1.4
One of the nice features in Java 5 is the annotation @Override. It prevents a base class changing underfoot without you realising. For example, consider the base class:
Now I can extend the Base
class and override the record
method as follows:
If the signature of the record
method changes in the Base
class, then a compilation error will occur when compiling SafeOvverride
. This is very useful for preventing subtle bugs.
Now naturally JDK 1.4 does not support `Override
, but you can simulate the behaviour using the Javadoc tool and the Javadoc tag {`inheritDoc}
. In JDK 1.4 write the SafeOverride
class as follows:
Now if the signature of the record
method changes in the Base
class, then Javadoc will report a warning like:
C:\\tmp\\SafeOverride.java:6: warning - @inheritDoc used but record(String) does not override or implement any method.