Rewrite the generic types in the add method using wildcards.
Don't change the logic.
Don't leave commented code.
Wildcards
- 16
Locked
Comments (3)
- Popular
- New
- Old
You must be signed in to leave a comment
Justin Smith
30 November 2022, 01:08
This took me forever to comprehend. But later I found out that this touches on a central concept of generics:
https://stackoverflow.com/questions/2723397/what-is-pecs-producer-extends-consumer-super
+1
Guadalupe Gagnon
21 November 2019, 04:02
This task was a real pain in the rear. DO NOT TOUCH THE TYPES AFTER STATIC:
public static <D, H extends D, S extends H> void add
Touch these and you fail. Trust me..... 33 times before I figured it out. Task is waaaaaay too vague.
Modify the types after both List and ListIterator declarations to maintain the same logic but use wildcards.
+3
Justin Smith
30 November 2022, 01:10
This may have been true when you posted this (CG does change their tasks sometimes and you posted that three years ago) but it's not true anymore. In fact the solution changes (and greatly simplifies) the part in bold.
+1