File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes annotations error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "annotations error " Watch "annotations error " New topic

annotations error

medhaj hambi
Ranch Hand

Joined: Jun 04, 2008
Posts: 34
Hi ,

I am using a small error when I am using override annotations. I fail to understand why. Can any body pl help me out ?

My code looks something like this :

public ArrayList<String> call() {
/* to guard against multiple invocations, synchronize on uniqueId */
String uniqueId = institutionId.intern();
synchronized (uniqueId) {
ArrayList<String> l = opacBaseList.get(uniqueId);
if (l == null) {
l = findOpacBase(uniqueId);
if (l.size() > 0) {
opacBaseList.put(uniqueId, l);
if (Config.verbose) {
Utils.printLog("OCLC: %s baseopacurl(s): %s", uniqueId, l);
return l;

When I comment out the annotation I am able to compile. If I remove the comment for the line ----> @override , it gives me the following error:

The method call() of type new Callable<ArrayList><String>>(){}
must override a superclass method

Am not able to figure out what could be the problem.
Sean Clark

Joined: Jul 15, 2009
Posts: 377


Basically this is used to help identify methods which override/implement methods from super classes.

An example would be the toString() method, typically most java classes will override this and you can use the @Override annotation to show.

I think it is correct to say that this annotation is optional and code will compile fine without, more of a visual aid.

The reason that you are getting this compilation error is because you don't have and method call() in any super class/interface.


I love this place!
Christophe Verré

Joined: Nov 24, 2005
Posts: 14688

This is also clearly mentioned in the java.lang.Override API.

[My Blog]
All roads lead to JavaRanch
Rob Spoor

Joined: Oct 27, 2005
Posts: 20275

And please UseCodeTags next time.

How To Ask Questions How To Answer Questions
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 15092

What class is your call() method in? What is the superclass of that class or what interfaces does it implement? Does a class higher up in the class hierarchy or one of the interfaces also have a call() method or not? Which Java version are you using?

Note that in Java 5, the @Override annotation could only be used with classes - not with interfaces. So if you implement a method from an interface, then in Java 5 you could not use the @Override annotation - it would give you a compiler error.

In Java 6 this was changed so that you can also use @Override for methods implemented from interfaces.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
medhaj hambi
Ranch Hand

Joined: Jun 04, 2008
Posts: 34
Thanks for the reply. I am using Java 6 Version. Also, this is how my class definition starts ...

I tried changing the method signature to Public ArrayList<String> call() throws Exception but that was of no use. Also , I am using Java 6 , so that shouldnt be the issue I guess. I have seen people implementing this sort of notation with callable class but I fail to understand why it doesnt compile.
John de Michele

Joined: Mar 09, 2009
Posts: 600

Shouldn't that signature be like this?:

medhaj hambi
Ranch Hand

Joined: Jun 04, 2008
Posts: 34
Well..I am decalring a class inside a method. I dont remember the terminology for that but it goes something like...

There is nothing wrong with the syntax as far as I know.
I agree. Here's the link:
subject: annotations error
It's not a secret anymore!