Created
December 6, 2015 04:43
-
-
Save parsonsmatt/0384e28017fcdfff9bb3 to your computer and use it in GitHub Desktop.
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
/** | |
* gets a record out of database by ID | |
* | |
* infers the type to use based on return | |
* | |
* RentalImpl r = Util.getById(10); | |
* | |
* @param c The implementation class name | |
* @param id the id of the instance you want | |
*/ | |
public static <T> T getById(Long id) { | |
return (T) DbConfig.withSession( | |
s -> s.get(((Class) ((ParameterizedType) new Object() { }.getClass().getEnclosingClass().getGenericSuperclass()).getActualTypeArguments()[0]), | |
id) | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment