0
enum itProfs {  
    private int sal;
    DEVELOPER(30), ANALYST(20); 
    itProfs(int sal){
        this.sal = sal;
    }
    public int getSal(){
        return sal;
    }   
}

What is the reason?

4
  • 2
    What error do you get ? It probably tells you exactly what the reason and the problem is ;) Commented Sep 22, 2011 at 3:47
  • 1
    Is there some reason you didn't make "itProfs" a class, and make DEVELOPER and ANALYST an enum??????? Commented Sep 22, 2011 at 3:53
  • Hi guys!! thank you for your advice. I know the error that the enumeration values first. I want to know the inner implementation in Java why. It is not so intuitive to me. Can you explain this deeper (i.e. memory allocations, internals? Btw this is just a sample code because I'm studying java deeper. Commented Sep 22, 2011 at 5:18
  • ok thanks. readability, that's the word! this feature in Java is just something new to me. @MeBigFatGuy thanks also!! grammar you said. Commented Sep 23, 2011 at 2:33

1 Answer 1

5

You should put enumeration values first.

enum itProfs {  
    DEVELOPER(30), ANALYST(20); 
    private int sal;
    itProfs(int sal){
        this.sal = sal;
    }
    public int getSal(){
        return sal;
    }   
}
Sign up to request clarification or add additional context in comments.

4 Comments

Hi guys!! thank you for your quick answer. I know the error that the enumeration values first. I want to know the inner implementation in Java why. It is not so intuitive to me. Can you explain this deeper (i.e. memory allocations, internals?
just cause. It's how the grammar was defined. They could have done it otherwise, but they didn't
@BrevisIunius, that has nothing to do with memory allocation. It's just a matter of syntax. I think that the main point is readability here. When someone is looking at enum code the first thing he wants to know is available values. And it would be pretty much uncomfortable to search all the class definition for it.
ok thanks. readability, that's the word! this feature in Java is just something new to me. @MeBigFatGuy thanks also!! grammar you said.

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.