Skip to content
Advertisement

Tag: wildcard

Wildcard not allowed for Iterable in Java

I have following code setup. But this is not allowed as wildcard is not allowed for Iterable. What actually Java tries to a achieve here by not allowing this? What modifications would get this working? Answer When a class instance is created, it invokes the initializer of the super type. But you can’t use wildcards for instance creation, hence your

Java Generics With Any Type

I’m trying to write a method in Java that will be able to add a custom Key object to an array, or change an already existing key in the array if there is one. However, I can’t seem to get it to work. The types that keys will use are primarily be String and Integer, but my universal approach doesn’t

Advertisement