This question already has an answer here:
- Get field values using reflection 4 answers
- How to determine an object's class? 7 answers
If I wanted to reflect on a Java collection, like this:
public class JavaColl {
Map<String,Integer> items;
}
val jmap = new HashMap[String, Integer]()
jmap.put("a", 5)
jmap.put("b", 6)
jmap.put("c", 7)
val inst = new co.blocke.test.JavaColl()
inst.setItems(jmap)
Now if I reflect on my JavaColl instance, I can find that items is of type Map, but is there a way to see that it is actually a HashMap, or is this lost to type erasure?
Aucun commentaire:
Enregistrer un commentaire