Forums Register Login

How do you extend a generic abstract class

+Pie Number of slices to send: Send
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?
+Pie Number of slices to send: Send
+Pie Number of slices to send: Send
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?
+Pie Number of slices to send: Send
 

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.
+Pie Number of slices to send: Send
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:
+Pie Number of slices to send: Send
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?
Humans and their filthy friendship brings nothing but trouble. My only solace is this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 5045 times.
Similar Threads
Confused over generics
need help about generics
confused with generics
Java Generics
ExamLab Generic Question
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 01:36:26.