I added wildcards:
Previously code looks:
I understand that here occur relationship producer-consumer or something similar.
Wildcard ? with super give me sureness that this List have ancestors and I can safely adding to it.
Wildcard ? with extends give me reliability that this list is descendant from S, this mean that from D too (because S extends H, H extends D)
But I don't understand difference between before code and after. I see that this give me more possibilities because before I could use only S and D class, now I have whole more spectrum of class to work.
Maybe someone give me some hints about this code because this Generics Day give me headache :)
(I added screens because I had problem with adding proper code)
Someone could tell me about difference?
Under discussion
Comments (5)
- Popular
- New
- Old
You must be signed in to leave a comment
Amantai
13 February, 05:28
0
Thomas
12 October 2023, 09:33useful
+2
Thomas
12 October 2023, 09:34useful
That was just the main method... here is the class, just past main into it. The 1000 char limit wasn't enough ;)
then you just need a Car class and a Cabriolet extends Car class. +2
matemate123
12 October 2023, 12:46
Nice example, Generics scares me a little less now. Thanks!
+1
Thomas
12 October 2023, 13:34
ups, the code was messed up... fixed that
+1