Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EnumMap constructor not found

Given that I have the requisite

import java.awt.Color;
import java.util.EnumMap;

and

enum Terrain { ... }

then as far as I can tell from the documentation, this should work

static EnumMap<Terrain, Color> colors = new EnumMap<Terrain, Color>(Terrain.class);

but it actually gives me this error

cannot find symbol
symbol  : constructor EnumMap()
location: class java.util.EnumMap<Terrain,java.awt.Color>
static EnumMap<Terrain,Color>colors=new EnumMap<Terrain, Color>();

What am I missing?

like image 214
rwallace Avatar asked Dec 13 '22 12:12

rwallace


2 Answers

The code the compiler is quoting doesn't match what you've claimed to have. It looks like you're not actually providing an argument to the constructor. This works fine, for example:

import java.util.EnumMap;

enum Foo {}

public class Test {    
    public static void main(String[] args) {
        EnumMap<Foo, String> map = new EnumMap<Foo, String>(Foo.class);
    }
}
like image 54
Jon Skeet Avatar answered Dec 22 '22 00:12

Jon Skeet


The error shows an no-arg constructor.

Are you sure you're looking at the right code/ have recompiled it?

like image 38
Puce Avatar answered Dec 21 '22 23:12

Puce