• 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
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Tim Cooke
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
  • Piet Souris
Bartenders:
  • Stephan van Hulst

generics problem

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:

 
Sheriff
Posts: 22813
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 15720
367
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Convince yourself it's @Override, not @override.
 
Marshal
Posts: 79831
388
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 79831
388
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 79831
388
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Hey, sticks and stones baby. And maybe a wee mention of my stuff:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic