Last active
December 29, 2015 16:19
-
-
Save Sutil/7696236 to your computer and use it in GitHub Desktop.
Exemplo de relacionamento com Enum
This file contains hidden or 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
| // Enum categoria | |
| public enum Categoria { | |
| LIVRO(1, "Livro"), | |
| PERIODICO(2, "Periódico"), | |
| ENCICLOPEDIA(3, "Enciclopédia"), | |
| CD(4, "CD"), | |
| DVD(5, "DVD"), | |
| BLUE_RAY(6, "Blue Ray"), | |
| FITA_CASSETE(7, "Fita Cassete"), | |
| DICIONARIO(8, "Dicionario"), | |
| MAPA(9, "Mapa"); | |
| private int codigo; | |
| private String descricao; | |
| private Categoria(int codigo, String descricao){ | |
| this.codigo = codigo; | |
| this.descricao = descricao; | |
| } | |
| public int getCodigo() { | |
| return codigo; | |
| } | |
| public String getDescricao() { | |
| return descricao; | |
| } | |
| } | |
| // classe que usa a categoria | |
| public class Obra { | |
| private Long id; | |
| private Categoria categoria; | |
| private String titulo; | |
| //.... gets and setters... | |
| } | |
| /// para seta categoria faz assim ... | |
| class Teste{ | |
| Obra obra = new Obra(); | |
| obra.setCategoria(Categoria.LIVRO); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment