3

I have an interface called SerializableL that is implemented by 3 different classes:

  • Product
  • Banner
  • Tag

I started refactoring and wanted to replace multiple paragraphs with multiple method calls.

public void load(ConcurrentHashMap<String, SerializableL> map, 
ArrayList<SerializableForL> preparedList)

I've written the following code and get the following error.

Code:

ConcurrentHashMap<String, SerializableForL> test = DBStore.Cache.get(tag);

Error:

Type mismatch: cannot convert from ConcurrentHashMap<String,Banner> to 
    ConcurrentHashMap<String,SerializableForL>

How can I do a workaround?

I want a way to cast (ConcurrentHashMap<String,Banner> to ConcurrentHashMap<String,SerializableForL>) .

A banner IS a SerializableForL.

Roman C
  • 48,723
  • 33
  • 63
  • 158
Menelaos
  • 22,383
  • 14
  • 83
  • 147

1 Answers1

4

You can't assign a Map<String,Banner> to a Map<String,SerializableForL> even if Banner implements SerializableForL.

However, if you only care about the values being SerializableForL you should be able to write:

ConcurrentMap<String, ? extends SerializableForL> test = DBStore.Cache.get(tag);
Community
  • 1
  • 1
assylias
  • 310,138
  • 72
  • 642
  • 762
  • 1
    +1 This is seriously some dark sorcery.... Sometimes problems like these make me want to go be a stripper heh. – Menelaos Feb 13 '14 at 16:53