tags:

views:

112

answers:

4

I am getting a "cannot be resolved" error when I try to do this:

class Tag{
   public static final int blah = 1231; 
}

enum Things{
    COOL (Tag.blah, "blah"); //error here
}

the compiler complains that it cannot find the Tag class on the line above.

+1  A: 

The following complete EnumTest.java file compile. I'm not sure what your problem is; there isn't enough information.

public class EnumTest {
    class Boo {
        static final int x = 42;
    }
    enum Things {
        X(Boo.x);
        Things(int x) { }
    }
}
polygenelubricants
hm.. what about if Boo is not an inner static class...
drozzy
@drozzy: if it's visible, it's fine. There's nothing special about `enum` and `static` class variables. Try `import static Tag.blah;` and see if you can even see `Tag` from `Things`.
polygenelubricants
Sorry mistake on my part... see update. Not sure what to do with the question... can't delete it.
drozzy
+3  A: 

Visibility is probably the error here. Your class Tag has default visibility, so I guess your enum is not in the same package. Use public class Tag

EDIT:

this compiles from inside a common outer class:

class Tag {
    public static final int blah = 1231;
}

enum Things {
    COOL(Tag.blah, "blah"); // error here

    private Things(final int i, final String s) {
    }
}
seanizer
A: 

Have you defined de contructor of COOL enum?, you are passing it parameters, but the default contructor not accept anyone

Telcontar
A: 

Well turns out the error was just stupidity on my part.

I was referring to a member variable, (blah in above example) that did not exist! So it wasn't resolving Tag.blah!

drozzy