My question is does it possible to write such a class:
public class Storage{
protected Map<String, ? extends Serializable> properties = new HashMap<>();
public <T extends Serializable> void put(String name , T value){
properties.put(name, value);
}
}
and when try to use it like this:
Storage s = new Storage();
List<String> list = new ArrayList<>();
s.put("name", list);
Through code above seems legit to me, it does not compile. I was looking into generics FAQ but can't find a solution, maybe it's not possible at all?
Here is compilation error
Error: where T is a type-variable: T extends Serializable declared
in method <T>put(String,T) where CAP#1 is a fresh type-variable: CAP#1
extends Serializable from capture of ? extends Serializable