SonarLint: java:S1319 for EnumMap

SonarLint (v2.0.0) tells me to “use collection interfaces” on an EnumMap.
The offending code:

EnumMap<BountyType, Integer> completions

Which displays: “Declarations should use Java collection interfaces such as “List” rather than specific implementation classes such as “LinkedList” (java:S1319)”
Map is not applicable here: It causes a type mismatch (for obvious reasons)

Hi Rhys,
Where is the type mismatch? Could you provide a reproducer?

Hello, here’s where all of this occurs - with the type mismatch

public BountyBook(Bounties plugin, Player player, Map<Integer, AbstractBounty> bounties, ItemStack book,
            Map<BountyType, Integer> completions, double creditsEarnt, int experienceEarnt) {

        this.plugin = plugin;
        this.player = player;
        this.bounties = bounties; = book;
        this.completions = completions;
        this.creditsEarnt = creditsEarnt;
        this.experienceEarnt = experienceEarnt;

        // Initialise the book data


Presumably the class field completions is declared as specific type EnumMap<...> as well. If only the type of the constructor parameter completions is changed to Map<...>, there will be a type mismatch, because it cannot be guaranteed that the argument is an EnumMap. The field needs to be a Map, too.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.