1

i try to define enum with int in it, but i have error in eclipse : "Syntax error on token "int", delete this token" my code:

 package util.enumurations;

public enum BooleanEnum
{  
  private int value;

  static
  {
    BooleanEnum[] arrayOfBooleanEnum = new BooleanEnum[2];
    arrayOfBooleanEnum[0] = False;
    arrayOfBooleanEnum[1] = True;
  }

  private BooleanEnum(int arg3)
  {
    int j;
    this.value = j;
  }

  public int getValue()
  {
    return this.value;
  }
}

3 Answers 3

5

The first thing in an enum have to be the declaration of the possible values.

public enum BooleanEnum
{  
  False(0), True(1);    

  private final int value;

  static
  {
    BooleanEnum[] arrayOfBooleanEnum = new BooleanEnum[2];
    arrayOfBooleanEnum[0] = False;
    arrayOfBooleanEnum[1] = True;
  }

  private BooleanEnum(int arg3)
  {
    this.value = arg3;
  }

  public int getValue()
  {
    return this.value;
  }
}
Sign up to request clarification or add additional context in comments.

1 Comment

Unless there is more to your enum, though, I'd just use java.lang.Boolean.
0

Use

java.lang.Boolean.TRUE, 
java.lang.Boolean.FALSE 

instead

Comments

0

Actually The body of an enum type may contain enum constants. An enum constant defines an instance of the enum type.

What you are trying to is You aren't gonna need it.

Just use a simple Boolean almost it self acts as ENUM for true false types.

Use Boolean.valueOf();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.