Please
Use Code Tags. It will preserve your formatting.
That's not even going to compile.
You should return something like
firstOrder - secondOrder can also work - until the difference becomes too large, and the result would be smaller than Integer.MIN_VALUE. It will then "wrap around" and become positive again.
You should check out Class.getFields() and Class.getDeclaredFields() to search for Collection and Map fields. The difference between those two methods is as follows:
- getFields returns only public (perhaps also protected, can't remember) fields, declared in the class and all super classes as well
- getDeclaredFields returns all fields (including private), but only those declared in the class itself.
It would be something like this:
That loop will make sure you get all fields, also those of the super classes.
Also, isAssignableFrom will check if the type represents Collection itself, or any subinterface or class that, directly or indirectly, implements Collection.