function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
d3developerd3developer 

Using Map with Enum ?

So, I tried to use a map with an Enum object (which I am told I can use as a datatype in the documentation), but it does not work.

 

 

Declaration in the class definition:

 

public enum Season {WINTER, SPRING}

 

Definition of Map in the constructor:

 

 

Map<Season,String> heatMap = new Map<Season,String> ();

 

 Error:

 

 

 

 

 

Error: Compile Error: Map by CustomCon.Season not allowed at line 27 column 37

 






 

anschoeweanschoewe

I have experienced the same issue.  Does anyone know if there is a solution to this?  Clearly enums are not just another datatype if this doesn't work.

 

Does anyone have any work-arounds for such a scenario?

 

Andrew

loneboatloneboat

I'd be interested in an answer to this as well.

Gustavo Adolfo Lopez 7Gustavo Adolfo Lopez 7
public enum Season { WINTER, SUMMER }

public static final Map<String, String> CHARACTERISTICS = new Map<String, String>{ 
        Season .WINTER.name() => 'Winter',  
        Season .SUMMER .name() => 'Summer',  
};

Try this.