I seem to have a bit of misunderstanding with Java Generics and I hope you can help me. I tried to create a map like so:
Map<Debater, int>
(Debater is an Interface I declared) but java complained about the int, so I did:
Map<Debater, Integer>
I suppose it’s because int is not a class while Integer is, is this correct?
Also, Now I get a Debater and I need to add 1 to its value in the map. How do I do that?
Yes, you are correct.
As for incrementing:
Autoboxing will take care of “switching” between the object and the primitive.
Note that this (as noted in the comments) will throw a
NullPointerExceptionif you don’t have a value for this debater in the map already. So if you want to do 2-in-1, it can be reworked as follows: