Created
February 22, 2011 14:40
-
-
Save tobyclemson/838759 to your computer and use it in GitHub Desktop.
A thing of beauty!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private <S, T extends S> void replace( | |
List<S> elements, | |
Class<T> classOfElementsToRemove, | |
Class<? extends T> classOfElementToAdd) { | |
elements.removeAll(toList(filterByType(elements, classOfElementsToRemove))); | |
try { | |
elements.add(classOfElementToAdd.newInstance()); | |
} catch (InstantiationException exception) { | |
throw new RuntimeException(exception); | |
} catch (IllegalAccessException exception) { | |
throw new RuntimeException(exception); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment