Need some help with (advanced?) Generics

What you're doing doesn't really make that much sense really. A generic is valid for that type. You can't have a single instance of a generic be valid for multiple types; that's not what those wildcards are for; because you'd end up with something that's not type safe.

That's why I'm asking if there's a solution that works differently - those aren't examples of what I'm doing, just examples of the things that don't work for what I'd like to do to help me explain what it is that I want.

If you want to be able to store 'anything' in that set

But I don't want to store "anything", I want to only store specific objects - objects of the same type as the key that I put in there and what I'm looking for is a solution to make this type-safe. I understand that generics probably can't express that and there might just not be such a solution, but i think that it's not an unreasonable thing to want to express.

I'm well aware that what you proposed works, I was just wondering if there is a more elegant way.

/r/javahelp Thread Parent