Skip to content

Instantly share code, notes, and snippets.

@vndmtrx
Last active September 23, 2016 11:07
Show Gist options
  • Save vndmtrx/1a56782c8d8179ba9e1ef6a27071ac0a to your computer and use it in GitHub Desktop.
Save vndmtrx/1a56782c8d8179ba9e1ef6a27071ac0a to your computer and use it in GitHub Desktop.
Classe genérica simples
class ClasseGenerica<T> {
T ob;
ClasseGenerica(T o) {
ob = o;
}
T getob() {
return ob;
}
void mostraTipo() {
System.out.println("O tipo de T é " + ob.getClass().getName());
}
public static void main(String args[]){
ClasseGenerica<String> cls1 = new ClasseGenerica<String>("Teste");
cls1.mostraTipo();
ClasseGenerica<Integer> cls2 = new ClasseGenerica<Integer>(10);
cls2.mostraTipo();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment