Home » Eclipse Projects » Eclipse Platform » Problem with enum (5.0) in Eclipse 3.1M5/M6
| Problem with enum (5.0) in Eclipse 3.1M5/M6 [message #283568] |
Tue, 05 April 2005 19:36  |
Eclipse User |
|
|
|
Problem with enum (5.0) in Eclipse 3.1M5/M6
The code below compiles and runs fine with Codeguide.
In Eclipse the source does not compile.
I have tried to define the enum members as static and/or private
and some other variations of the source code,
but to no avail.
I have checked all settings in Prefernces/Java/Compiler
to be 5.0 compliant.
Any suggestions why this won't work in Eclipse?
------------------------------------------------------------ ---------------
public class XYZ
{
//...
// ERROR
public enum ItemType{DBL, INT, MEMO, TXT, DATE, BOOL, COMBO, NONE };
//...
public enum QMode //inner class //<< ERROR <<
{
EQUAL (1, " = "),
GREATER(2, " > "),
LESSER(3, " < "),
GREATEROREQUAL(4, " >= "),
LESSEROREQUAL(5, " <= "),
LIKE(6, " LIKE "),
BETWEEN(7, " BETWEEN ");
int f_qm; String f_sql;
// ERROR
public QMode(int qm, String sql ) {f_qm=qm; f_sql=sql;}
public String toString(){return f_sql;}
}//QMode
//...
}// XYZ end class
__________________________________________________
Severity Description Resource In Folder
Location Creation Time
2 Illegal modifier for the member enum ItemType; only public,
protected, private, static & abstract are permitted XYZ.java
2 The member enum ItemType must be defined inside a static
member type XYZ.java
2 The member enum QMode must be defined inside a static member
type XYZ.java
2 Illegal modifier for the enum constructor; only private is
permitted. XYZ.java
___________________________________________________
|
|
| | |
| Re: Problem with enum (5.0) in Eclipse 3.1M5/M6 - correction (javac) [message #283582 is a reply to message #283581] |
Wed, 06 April 2005 08:54   |
Eclipse User |
|
|
|
Below I write that the sample code would compile with javac.
Thats wrong: javac 1.5.0_01 also outputs an error as Oivier pointed out before:
command prompt> javac TestInnerClassWithEnum.java
TestInnerClassWithEnum.java:22: enum declarations allowed only in static contexts
public enum PublicEnum {ENE, MENE, MUH};
I'm getting really confused now, as i actually never saw this error before and
actuall program is running without problems.
Lophiomys
On Wed, 06 Apr 2005 14:42:23 +0200, Lo Phi <lophiomys@gmx.at> wrote:
>Salut Olivier,
>Thanks for your reply.
>
>Theres nothing wrong with the code.
>I've compiled a test case below.
>The problem is that Eclipse 3.1M6 is not accepting
>a public enum inside a (non-static) public inner class.
>Declaring the inner class as static is not a possible workaround for me.
>
>Even so Eclipse displays an error flag, the code actually
>compiles and runs (as it does with Codeguide and javac).
>
>I think, I'll report it as a bug.
>
>Kind Regards,
>et avec mes salutations distinguees,
>Lophiomys
>
> ------------------------------------------------------------ ---
>public class TestInnerClassWithEnum
>{
> public static void main(String[] args)
> {
> System.out.println("hellaaaargh ... here we are");
> TestInnerClassWithEnum ticwe= new TestInnerClassWithEnum();
> }
>
> public TestInnerClassWithEnum()
> {
> // testing inner class with enum
> InnerClass ic= new InnerClass(InnerClass.PublicEnum.MUH);
> System.out.println(ic.getCowWords());
> // tesing end
> }
>
> public class InnerClass
> {
>//Severity Description Resource In Folder Location Creation Time
>//2 The member enum PublicEnum must be defined inside a static member type TestInnerClassWithEnum.java JoHoTestingEclipse/JoHoTesting line 22 6. April 2005 14:23:37
>// ...
>//A workaround: When InnerClass is declared as "static" the error flag disappers.
> public enum PublicEnum {ENE, MENE, MUH};
> private final PublicEnum cow;
> InnerClass(PublicEnum publicEnemy)
> {
> cow= publicEnemy;
> }
> public String getCowWords()
> {
> return PublicEnum.MUH == cow ? "Mooooooooohhhhh": "The cow is counting.";
> }
> }//InnerClass
>}//TestInnerClassWithEnum
> ------------------------------------------------------------
|
|
|
| Re: Problem with enum (5.0) in Eclipse 3.1M5/M6 - correction (javac) [message #283587 is a reply to message #283582] |
Wed, 06 April 2005 11:21  |
Eclipse User |
|
|
|
Originally posted by: olivier_thomann.NOca.ibm.comSPAM
Lophiomys a écrit :
> Below I write that the sample code would compile with javac.
> Thats wrong: javac 1.5.0_01 also outputs an error as Oivier pointed out before:
>
> command prompt> javac TestInnerClassWithEnum.java
> TestInnerClassWithEnum.java:22: enum declarations allowed only in static contexts
> public enum PublicEnum {ENE, MENE, MUH};
Then we can consider this problem as closed.
We behave as javac does as far as I can tell.
Thanks for the report anyway,
Olivier
|
|
|
Goto Forum:
Current Time: Sun Nov 09 14:13:32 EST 2025
Powered by FUDForum. Page generated in 0.03676 seconds
|