Enum returning me null pointer

0

My Enum is returning Null Pointer when relaying this call:

  System.out.println(DefinicaoSCM.getDefinicaoSCMPorDisciplina(Disciplina.IMPLEMENTACAO));

Implementation:

public enum DefinicaoSCM
{
   DESCONHECIDO(null, "NA", "NA"),
   IMPLANTACAO(Disciplina.IMPLANTACAO, "ipl_", "/Implantacao"),
   IMPLEMENTACAO(Disciplina.IMPLEMENTACAO, "imp_", "/Implementacao", "/Documentacao", "/Implantacao"),
   INTERFACE_GRAFICA(Disciplina.INTERFACE_GRAFICA, "ifg_", "/Design"),
   PROJETO(Disciplina.PROJETO, "prj_", "/Projeto"),
   REQUISITO(Disciplina.REQUISITO, "req_", "/Requisitos"),
   TESTE(Disciplina.TESTE, "tst_", "/Teste");

   private static Map<Disciplina, DefinicaoSCM> definicaoSCMPorDisciplina;
   private Disciplina disciplina;



   public static DefinicaoSCM getDefinicaoSCMPorDisciplina(Disciplina disciplina)
   {
      return definicaoSCMPorDisciplina.get(disciplina);
   }
    
asked by anonymous 25.11.2016 / 18:32

1 answer

0

To use a Map in an Enum, I was only able to use the ImmutableMap from Guava , in your example, would look like this:

private static final Map<Disciplina, DefinicaoSCM> definicaoSCMPorDisciplina = ImmutableMap.<Disciplina, DefinicaoSCM>builder()
                    .put(Disciplina.IMPLANTACAO, new DefinicaoSCM())
                    .put(Disciplina.INTERFACE_GRAFICA, new DefinicaoSCM())
                    .put(Disciplina.PROJETO, new DefinicaoSCM())
                    .put(Disciplina.REQUISITO, new DefinicaoSCM())
                    .put(Disciplina.TESTE, new DefinicaoSCM())
                    .build();

Map access continues in the same way .get(key) .

    
28.11.2016 / 12:53