File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
Author

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 :


//@Override
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
Rancher

Joined: Jul 15, 2009
Posts: 377

Hey,

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.

Sean


I love this place!
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

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


[My Blog]
All roads lead to JavaRanch
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19670
    
  18

And please UseCodeTags next time.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14110
    
  16

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 7 API documentation
Scala Notes - My blog about Scala
medhaj hambi
Ranch Hand

Joined: Jun 04, 2008
Posts: 34
Hi,
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
Rancher

Joined: Mar 09, 2009
Posts: 600
Medhaj:

Shouldn't that signature be like this?:



John.
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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: annotations error