Slide 55
Slide 55 text
@holly_cummins #RedHat
private static int extractSize(Object it) {
if (it instanceof Collection) {
return ((Collection>) it).size();
} else if (it instanceof Map) {
return ((Map, ?>) it).size();
} else if (it.getClass().isArray()) {
return Array.getLength(it);
} else if (it instanceof Integer) {
return ((Integer) it);
}
return 10;
}
// Note that we intentionally use "instanceof" to test interfaces as the last resort in order to mitigate the "type pollution"
// See https://github.com/RedHatPerf/type-pollution-agent for more information
if (it instanceof AbstractCollection) {
return ((AbstractCollection>) it).size();
} else if (it instanceof AbstractMap) {
return ((AbstractMap, ?>) it).size();
} else if (it instanceof Collection) {
return ((Collection>) it).size();
} else if (it instanceof Map) {
return ((Map, ?>) it).size();
}
return 10;
}