• 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

How do you extend a generic abstract class

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Code reference Generics Question


At Line 2, I tried
class SubABS<K> extends ABS<K>,
class SubABS<K extends Number> extends ABS<K extends Number>

and all variations of this, finally it compiles with class SubABS extends ABS, and the warning that raw types are used.

When I use Eclipse to implement the unimplemented methods, I get the method on 3. When I used the exact signature in 1, I get an error
Multiple markers at this line
- Name clash: The method useMe(ABS<? extends K>) of type SubABS has the same erasure as useMe(ABS) of type
ABS but does not override it
- The method useMe(ABS<? extends K>) of type SubABS must override a superclass method

How can I extend this abstract method correctly using Generics and why am I getting the above issues?
 
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
 
Seema Kekre
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Now it all compiles fine.
I infer that ABS<K> is required because we have already defined what K is in the abstract class, then why do I need to redefine K for ABS2?
 
Ranch Hand
Posts: 75
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Seema Kekre wrote: Now it all compiles fine.
I infer that ABS<K> is required because we have already defined what K is in the abstract class, then why do I need to redefine K for ABS2?



I have the same question.
 
Christophe Verré
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
You need to tell which class you are actually using for ABS. If you are not using any generic type in ABS2, you can also define the class like :

or refine it to Double for example:
 
Seema Kekre
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So either you use ABS to define the type of the subclass if you dont want the subclass to use Generics, or use Generics wrt K's definition of the superclass. Right?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic