File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

generics problem

 
Kurro Zaki
Greenhorn
Posts: 14
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey guys
I create an abstract class with generic parameter T and an abstract method that return T.
The I extended the abstract class (like this: ImageLoader extends Retryable<Image>) and now logicall the method should return Image instead of T.
If i use implement abstract methods in netbeans the return type become Image (as expected) however netbeans, and the java compiler keep complaining
that the class doesn't implement all abstract methods :s
 
Steve Luke
Bartender
Pie
Posts: 4181
21
IntelliJ IDE Java Python
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think this is a generics problem. The problem is that the throws clause is part of the method signature. When you attempt to override the method you do not provide the throws clause, so the method doesn't have the same signature as the one you are trying to override - and therefore does not override it.


should fix the problem
 
Kurro Zaki
Greenhorn
Posts: 14
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's not the problem because I made silly mistake copying the code to the forum. I actually did write the throws clause in netbeans.
Sorry for that (updating my post now :p)
 
Steve Luke
Bartender
Pie
Posts: 4181
21
IntelliJ IDE Java Python
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay, then the problem is not in the code you are showing us. This compiles just fine in eclipse, IntelliJ, and on command line:

 
Rob Spoor
Sheriff
Pie
Posts: 20372
44
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, you can drop any exception from the overridden method's throws list, and even specialize it (e.g. declare to throw FileNotFoundException where the overridden method throws the more general IOException).

I've tried your example, replacing the "a bit of code" with "Image image = null;", and it compiled successfully. Are you sure that Retryable doesn't have any other abstract methods? Also, Eclipse can give quick fixes, including implementing the missing methods. I'm sure Netbeans can do the same. That way you can see which methods you forgot to override.
 
Kurro Zaki
Greenhorn
Posts: 14
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sometimes pc's can drive someone crazy

I solved the problem by first removing the @override. Then netbeans and the compiler just accepted.
After that I could just put the @override back with no problems :s

Thanks a lot for the help :p
 
Stephan van Hulst
Bartender
Pie
Posts: 4826
34
Chrome Netbeans IDE Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Convince yourself it's @Override, not @override.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47229
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kurro Zaki wrote: . . . updating my post now :p)
No, please don't update your post. It makes Steve Luke's response look like nonsense.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47229
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kurro Zaki wrote: . . . I solved the problem by first removing the @override. . . .
What override annotation? You didn't have one in the code you posted: please read this. I have come upon this thread late and can't understand it because of these changes. And SvH is right: it's @Override not @override.
 
Kurro Zaki
Greenhorn
Posts: 14
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Man I'm getting to used to netbeans doing stuff for me the I forgot that @Override is with a capital. It just a capital not some thing that's very wrong. Netbeans would have complained :p
Also I didn't include it because it's just a hint, it's not strictly necessary but in netbeans it had @Override and that shouldn't make a difference (at least I think so)
 
Campbell Ritchie
Sheriff
Pie
Posts: 47229
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kurro Zaki wrote: . . . It just a capital not some thing that's very wrong. . . .
You are using a case-sensitive language; that capital letter missed out is very wrong. You need to become obsessional about such things. You are giving me the impression that you are depending on NetBeans all the time, and that dependency is hindering your learning.
Also I didn't include it because it's just a hint, it's not strictly necessary . . .
But you mentioned it later, which made the discussion very confusing.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic