Here is a sample jaxb class that I defined from scratch. When I try generating schema for this class using JAXB, it guesses correctly that the itemType of the list as “int”
Doesn’t JVM throw away generics at runtime? By doing that the container type of List is lost at runtime but still, jaxb knows the itemType is Integer. I am very curious as to how this is accomplished by the jaxb framework. Any ideas?
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "int-list")
public class IntegerList{
@XmlValue
private List<Integer> values;
public List<Integer> getValues() {
return values;
}
public void setValues(List<Integer> values) {
this.values = values;
}
}
Corresponding schema generated using JAXBContext.generateSchema:
<xs:simpleType name="int-list">
<xs:list itemType="xs:int"/>
</xs:simpleType>
Yes, with respect to actual bytecode (well, it’s the compiler that throws them away). But the generic type information of classes and certain variables can still be gleaned at runtime by using reflection. For example:
Just a guess, but JAXB is likely doing something similar and then mapping
Integer.classtoint.class.