How Can I create a generic HashMap to insert collections and objects?
Declare the hash map as
Map<String,Object> params = new HashMap<String,Object>();
You can keep the declaration of
public void method(Map<String, ?> params);
as it is, as long as the method only every tries to read from the map.
You need to change
Map<String,?>params=new HashMap<String,? >
to like this
Map<String,Object>params=new HashMap<String,Object>()
But its not good practice to put all type of objects into single map. Better you can create POJO and add it to map.
All classes in Java extends Object. so you can use Object for a value type in a map, like
Map<String, Object> params = new HashMap<String, Object>