Skip to main content



      Home
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 Go to next message
Eclipse UserFriend
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 [message #283571 is a reply to message #283568] Tue, 05 April 2005 20:24 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: olivier_thomann.NOca.ibm.comSPAM

Lo Phi a écrit :
> 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?
You must have something else that is wrong.

With your test case I get using M6:

----------
1. ERROR in d:\tests_sources\X.java
(at line 20)
public QMode(int qm, String sql ) {f_qm=qm; f_sql=sql;}
^^^^^^^^^^^^^^^^^^^^^^^^^^
Illegal modifier for the enum constructor; only private is permitted.
----------
1 problem (1 error)

And this doesn't compile as well with javac.
X.java:20: modifier public not allowed here
public QMode(int qm, String sql ) {f_qm=qm; f_sql=sql;}
^
1 error

If you remove the public keyword, both compile fine. Could you please
provide a complete test case and enter a bug report against JDT/Core?

Thanks
--
Olivier
Re: Problem with enum (5.0) in Eclipse 3.1M5/M6 [message #283581 is a reply to message #283571] Wed, 06 April 2005 08:42 Go to previous messageGo to next message
Eclipse UserFriend
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 #283582 is a reply to message #283581] Wed, 06 April 2005 08:54 Go to previous messageGo to next message
Eclipse UserFriend
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 Go to previous message
Eclipse UserFriend
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
Previous Topic:error starting plugin migrated from 2.1
Next Topic:minimal column width in TableWrapLayout
Goto Forum:
  


Current Time: Sun Nov 09 14:15:11 EST 2025

Powered by FUDForum. Page generated in 0.04596 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top