android and JDK compliance – how to fix @override errors



From time to time when working with other people’s projects I run into build errors that are caused by the @override annotation. It took me a while to understand why that was happening as I was usually able to solve it by simply deleting the @override annotation or adding it where needed.

an example of an error caused by @override

Turns out the problem is because of of a mismatch in the JDK different developers are using.

Starting in Java 6 the @override annotation no longer applies to interface methods. So most methods derived from an interface no longer need them. They are however needed with Java 5.  The problem arises if a dev with Java 5 creates an android project, By default the project will get set with whatever JDK compliance is valid in their environment, in this  Java 1.5. If a developer with java 6 opens the same project all  @override annotations will be flagged as errors when appearing above interface methods.

Thankfully, this is easy to fix.

You simply need to go to your android project properties, choose the java compiler and select the appropriate JDK compliance level for your environment.

Project Properties > Java Compiler

Click enable project specific settings to be able to select the appropriate JDK version to use.

Don’t know which hava version you have? No problem. Simply type java -version in your command line to get that info. It will look like below

how to check your jdk version

Don’t want to have to do this every time you and another developer have mismatching JDKs? You can configure it as a default on your workspace.

From the same Java Compiler properties window, click “Configure Workspace Settings”

That will bring you to the window below where you can choose your default Compiler compliance level for your JDK Compliance.

configure your default workspace settings

As per usual i’d like to thank the fine folks @ stackoverflow for their help.

3 comments on “android and JDK compliance – how to fix @override errors”

  1. Pingback: @Override annotation error (android prefs) - Android Questions - Developers Q & A

Leave a Reply

Your email address will not be published. Required fields are marked *