All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sonar.l10n.java.rules.squid.S1640.html Maven / Gradle / Ivy

There is a newer version: 8.6.0.37351
Show newest version

When all the keys of a Map are values from the same enum, the Map can be replaced with an EnumMap, which can be much more efficient than other sets because the underlying data structure is a simple array.

Noncompliant Code Example

public class MyClass {

  public enum COLOR {
    RED, GREEN, BLUE, ORANGE;
  }

  public void mapMood() {
    Map<COLOR, String> moodMap = new HashMap<COLOR, String> ();
  }
}

Compliant Solution

public class MyClass {

  public enum COLOR {
    RED, GREEN, BLUE, ORANGE;
  }

  public void mapMood() {
    EnumMap<COLOR, String> moodMap = new EnumMap<COLOR, String> (COLOR.class);
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy