aspose file tools*
The moose likes Java in General and the fly likes generics problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "generics problem" Watch "generics problem" New topic
Author

generics problem

Kurro Zaki
Greenhorn

Joined: Dec 08, 2009
Posts: 14
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

Joined: Jan 28, 2003
Posts: 4180
    
  21

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


Steve
Kurro Zaki
Greenhorn

Joined: Dec 08, 2009
Posts: 14
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

Joined: Jan 28, 2003
Posts: 4180
    
  21

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

Joined: Oct 27, 2005
Posts: 19672
    
  18

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Kurro Zaki
Greenhorn

Joined: Dec 08, 2009
Posts: 14
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

Joined: Sep 20, 2010
Posts: 3615
    
  14

Convince yourself it's @Override, not @override.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38412
    
  23
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

Joined: Oct 13, 2005
Posts: 38412
    
  23
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

Joined: Dec 08, 2009
Posts: 14
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

Joined: Oct 13, 2005
Posts: 38412
    
  23
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.
 
Don't get me started about those stupid light bulbs.
 
subject: generics problem