Oh my. Reflection on generics. That's not always nice. So, here goes. As can be easily found, it is possible to determine the actual type of a generic class at runtime. And in the code we get a number of lists<>... and we want to sort them by class hierarchy (so, String extends Object, and thus List<String> should go after List<Object>) Our compare method then needs to look like this: compare( List left, List right) { Type type = left.getClass().getGenericSuperclass() if(type instanceof ParameterizedType) {// it is a generic ParameterizedType pType = (ParameterizedType) type; Type[] actualTypes = pType.getActualTypeArguments(); // and then we have an array, which in this case should be String.class and Object.class, which we can then compare } ... } This is nice, but spring kinda has the problem that those objects *might* be more then they are... they might be AOP'd! In that case, we do not get the actual objects, but proxie...
This is a simple blog to help me remember those cool code snippets which I used. Either by copy, or by cobbling... I do not intend this to be read by people except for me and my bad mind.