Skip to content

Instantly share code, notes, and snippets.

@tadams
Created June 26, 2015 18:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tadams/aff12b6d3aa504bb232e to your computer and use it in GitHub Desktop.
Save tadams/aff12b6d3aa504bb232e to your computer and use it in GitHub Desktop.
public List<Class> buildClassHierarchy(Class baseClass) {
List<Class> superClasses = new ArrayList<>();
Class clazz = baseClass;
while(neededInHierarchy(clazz)) {
superClasses.add(clazz);
clazz = clazz.getSuperclass();
}
return superClasses;
}
private boolean neededInHierarchy(Class clazz) {
if (isNull(clazz) || clazz.equals(Object.class)) {
return false;
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment