Enums in inner classes

G

G Winstanley

Jus a quick one...now I've finally got hold of v1.5 I'm trying to use an
enum in a private final inner class, but I get the following message from
the compiler in NetBeans 4.0b2:

init:
deps-jar:
Compiling 1 source file to P:\NetBeans Projects\ProjectX\build\classes
P:\NetBeans Projects\ProjectX\src\Foo.java:7: modifier not allowed here
private enum Status{ONE, TWO, THREE, FOUR}
1 error
BUILD FAILED (total time: 0 seconds)


The class is defined as:

public class Foo
{
private final class Bar
{
private enum Status {ONE, TWO, THREE, FOUR}
// ...etc...
}
}


Any ideas which modifier it's got a problem with? I've tried removing the
private modifier and that has no effect. It seems that it's just not happy
having an enum within an inner class, but I can't find reference to this in
the enum documentation that comes with JDK1.5.

Stan
 
B

Boudewijn Dijkstra

G Winstanley said:
Jus a quick one...now I've finally got hold of v1.5 I'm trying to use
an enum in a private final inner class, but I get the following
message from the compiler in NetBeans 4.0b2:

init:
deps-jar:
Compiling 1 source file to P:\NetBeans Projects\ProjectX\build\classes
P:\NetBeans Projects\ProjectX\src\Foo.java:7: modifier not allowed
here private enum Status{ONE, TWO, THREE, FOUR}
1 error
BUILD FAILED (total time: 0 seconds)


The class is defined as:

public class Foo
{
private final class Bar
{
private enum Status {ONE, TWO, THREE, FOUR}
// ...etc...
}
}


Any ideas which modifier it's got a problem with?

How about the static modifier?
 
X

xarax

G Winstanley said:
Jus a quick one...now I've finally got hold of v1.5 I'm trying to use an
enum in a private final inner class, but I get the following message from
the compiler in NetBeans 4.0b2:

init:
deps-jar:
Compiling 1 source file to P:\NetBeans Projects\ProjectX\build\classes
P:\NetBeans Projects\ProjectX\src\Foo.java:7: modifier not allowed here
private enum Status{ONE, TWO, THREE, FOUR}
1 error
BUILD FAILED (total time: 0 seconds)


The class is defined as:

public class Foo
{
private final class Bar
{
private enum Status {ONE, TWO, THREE, FOUR}
// ...etc...
}
}


Any ideas which modifier it's got a problem with? I've tried removing the
private modifier and that has no effect. It seems that it's just not happy
having an enum within an inner class, but I can't find reference to this in
the enum documentation that comes with JDK1.5.

Did you specify the -source 1.5 on the compiler command line?
How about specify "static" on the "private enum" declaration
(I don't know whether an enum can be an inner class; likely
not.)
 
G

G Winstanley

How about the static modifier?

Same problem arises with any modifier as far as I can see. I've tried the
obvious ones like static, final, and public to see if needs more scope, but
nothing allows it to compile successfully.

Stan
 
G

G Winstanley

Did you specify the -source 1.5 on the compiler command line?
How about specify "static" on the "private enum" declaration
(I don't know whether an enum can be an inner class; likely
not.)

Yes, it's all setup for 1.5 compilation, but still does this!

Stan
 
A

Alan Moore

G Winstanley said:
Jus a quick one...now I've finally got hold of v1.5 I'm trying to use an
enum in a private final inner class, but I get the following message from
the compiler in NetBeans 4.0b2:

init:
deps-jar:
Compiling 1 source file to P:\NetBeans Projects\ProjectX\build\classes
P:\NetBeans Projects\ProjectX\src\Foo.java:7: modifier not allowed here
private enum Status{ONE, TWO, THREE, FOUR}
1 error
BUILD FAILED (total time: 0 seconds)


The class is defined as:

public class Foo
{
private final class Bar
{
private enum Status {ONE, TWO, THREE, FOUR}
// ...etc...
}
}


Any ideas which modifier it's got a problem with? I've tried removing the
private modifier and that has no effect. It seems that it's just not happy
having an enum within an inner class, but I can't find reference to this in
the enum documentation that comes with JDK1.5.

I think the modifier it's complaining about is "static"--enums are
implicitly static, and you can't declare a static class inside a
non-static inner class.
 
G

G Winstanley

I think the modifier it's complaining about is "static"--enums are
implicitly static, and you can't declare a static class inside a
non-static inner class.

Ah ha! Of course, I should have realized that. Thanks for pointing out the
obvious. Of course it now compiles.

Thanks again.
Stan
 
B

Boudewijn Dijkstra

G Winstanley said:
Ah ha! Of course, I should have realized that. Thanks for pointing out
the obvious. Of course it now compiles.

Huh? In your reply to my last post in this thread, you said you already tried
static...
 
X

xarax

Boudewijn Dijkstra said:
Huh? In your reply to my last post in this thread, you said you already tried
static...

He tried "static" on the enum declaration, not
on the enclosing inner class.
 
G

G Winstanley

He tried "static" on the enum declaration, not
on the enclosing inner class.

Precisely. Annoying really, as it's exactly the sort of thing that gives you
one of those Homer Simpson "Doh" moments when you see the solution.

Thanks for the help all. Classes now enumerated in full.

Stan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top