4

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?

rwallace
  • 31,405
  • 40
  • 123
  • 242

2 Answers2

12

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);
    }
}
Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
  • Ah, you're right, what actually happened was Netbeans (6.9) had started failing to recognize the source file as modified and therefore failing to save it even when explicitly directed to do so. No idea why Netbeans glitched like that, but copy pasting to UltraEdit and saving from there, solved the problem. – rwallace Jun 21 '11 at 10:58
1

The error shows an no-arg constructor.

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

Puce
  • 37,247
  • 13
  • 80
  • 152