• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

annotations error

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 377
Android Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is also clearly mentioned in the java.lang.Override API.
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And please UseCodeTags next time.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 600
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic