1

I am getting the error classes cannot directly extends java.lang.enum in my following code

public final class ConversionMode extends Enum
{

public static final ConversionMode TO_XLIFF;
public static final ConversionMode FROM_XLIFF;
private static final ConversionMode $VALUES[];

public static final ConversionMode[] values()
{
    return (ConversionMode[])$VALUES.clone();
}

public static ConversionMode valueOf(String s)
{
    return (ConversionMode)Enum.valueOf(file2xliff4j/ConversionMode, s);
}

private ConversionMode(String s, int i)
{
    super(s, i);
}

static 
{
    TO_XLIFF = new ConversionMode("TO_XLIFF", 0);
    FROM_XLIFF = new ConversionMode("FROM_XLIFF", 1);
    $VALUES = (new ConversionMode[] {
        TO_XLIFF, FROM_XLIFF
    });
}
}

I also refer this link, but I am getting it properly so please give me the solution what I need to do?

4
  • why are you extending a class with enum? What is your purpose? Commented Sep 28, 2013 at 6:01
  • @PrasadKharkar: Possibly trying to recompile disassembled code? Commented Sep 28, 2013 at 6:02
  • This will help you . thejavageek.com/2013/08/01/why-use-enumerations-in-java Commented Sep 28, 2013 at 6:11
  • @Prasad Kharkar if(mode.equals(ConversionMode.TO_XLIFF) && filetype == null) { return "Specify the file type."; } In this function i want to access ConversionMode value what should i need to do? Commented Sep 28, 2013 at 12:04

3 Answers 3

8

That's not how you create an enum in Java. Here's how you do it:

public enum ConversionMode {
    TO_XLIFF,
    FROM_XLIFF
}

That's all. The values(), valueOf(), ordinal() and other enum methods are implemented for you.

As always in Java, there is a tutorial about enums.

Sign up to request clarification or add additional context in comments.

Comments

2

No you cannot extends ENUM

JLS#8.9

An enum type is implicitly final unless it contains at least one enum constant that has a class body.

Example

enum Color {
    RED, GREEN, BLUE;

}

If you see the Language Specification, a complete example is there how to use Enum and getting values etc ...

Comments

0

This is not how to make enums. You don't extend enum.

public enum ConversionMode {
    TO_XLIFF,
    FROM_XLIFF,
...

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.