I have something like:
Field [] fields = claz.getDeclaredFields();
for(Field f : fields){
f.setAccessible(true);
if(f.getType().equals(List.class)){
Method m = f.getType().getMethod("size");
int length = (Integer)m.invoke(f.get(node));
System.out.println("length "+ length);
}
}
it does work, but I'm wondering to know if there is any other good approaches, like something that will work for all other collections (TreeSet, HashSet, etc...), or the only way is that, I have to check for each type like what I already have?
thanks
if (node instanceof Collection) length = ((Collection)node).size()
?if (f.get(node) instanceof Collection)
, so reflection would still be used to access the field.node
is the object whose fields are checked...