Skip to content
Advertisement

Specify Map in Java generics

I have the following interface:

JavaScript

Then I want to create a concrete class that takes CacheKey object as input and Map<String, List<String>> object as output. A conceptual example is as follows:

JavaScript

Where CacheKey is like:

JavaScript

I have seen red wavy lines from IDE by using the implementation in the example above. But I couldn’t fin the correct format to match the generics <K, V> in the interface.

Could anyone good at Java please correct me? Thank you in advance!

Advertisement

Answer

By putting <> after the name of the class that you’re defining, you’re declaring tokens to be used as generics. But you don’t want that, you just want to fill existing generic type arguments.

So just omit the first pair of <>:

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement