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
  • 49,761
  • 33
  • 66
  • 176
Menelaos
  • 23,508
  • 18
  • 90
  • 155

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
  • 321,522
  • 82
  • 660
  • 783
  • 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