mercredi 25 février 2015

Reflect Map in Java

In Java, having shared storage:



final Map<String, Car> cars = (numberOfThreads == 1)
? new HashMap<String, Car>()
: new ConcurrentHashMap<String, Car>();


then in the run() method of a thread worker class I want to store concurrently data into the cars map. For that I need to downcast to an appropriate hashmap instance. I could use if (numberOfThreads == 1) but I guess it is possible to reflect the cars object - how can I use Java Reflection API here?






Aucun commentaire:

Enregistrer un commentaire