| 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: 14685
|
|
|
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: 19232
|
|
|
And please UseCodeTags next time.
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
Jesper de Jong
Java Cowboy
Bartender
Joined: Aug 16, 2005
Posts: 12956
|
|
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.
|
 |
 |
|
|
subject: annotations error
|
|
|