Last active
August 29, 2015 14:06
-
-
Save pedro-hos/c47ac163b05195a25959 to your computer and use it in GitHub Desktop.
Retorna Classe por Reflection
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
/** | |
* @author Pedro Hos<br> | |
* | |
* Utilizando Exemplo de Eduardo Guerra! | |
* https://groups.google.com/forum | |
* /#!topic/projeto-oo-guiado-por-padroes/pOIiOD9cifs | |
* | |
* Este método retorna o tipo da Classe, dessa maneira não é | |
* necessário cada Service expor seu tipo!!!! | |
* | |
* @return Class<T> | |
*/ | |
@SuppressWarnings({ "unchecked" }) | |
private Class<T> retornaTipo() { | |
Class<?> clazz = this.getClass(); | |
while (!clazz.getSuperclass().equals(NomeClasse.class)) { | |
clazz = clazz.getSuperclass(); | |
} | |
ParameterizedType tipoGenerico = (ParameterizedType) clazz.getGenericSuperclass(); | |
return (Class<T>) tipoGenerico.getActualTypeArguments()[0]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment