This week's giveaway is in the Spring forum.
We're giving away four copies of Learn Spring Security (video course) and have Eugen Paraschiv on-line!
See this thread for details.
Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

annotations error

 
medhaj hambi
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 377
Android Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is also clearly mentioned in the java.lang.Override API.
 
Rob Spoor
Sheriff
Pie
Posts: 20492
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And please UseCodeTags next time.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15203
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
medhaj hambi
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 600
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Medhaj:

Shouldn't that signature be like this?:



John.
 
medhaj hambi
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic