Tuesday, August 23, 2011

@Override annotation in Java 5 vs 6

I was porting a Java 6 project to Java 5 today due to requirements, and I came up with a feature difference that I was not aware of before. @Override annotation was introduced in Java 5 to mark methods that have to override methods from superclass, and to give compiler error when such overrides do not occur. However only since Java 6 you can use @Override in order to mark methods that implement the methods from interface, thus putting @Override in a method that implements method of the interface, will result in compile error in Java 5. It was somehow forgotten to be put in Java SE 6 API documentation, but was promised to be fixed in Java 7 API documentation. Blog entry from Oracle: http://blogs.oracle.com/ahe/entry/override_snafu

2 comments: