Search code examples
javaeclipsecoding-styleenumsnaming-conventions

Should Java member enum types be capitalized?


Anal question here: we have Java enums which are their own classes, and enums which are members of a class:

public enum reportType { ...

Every time I see this it jars me* because when I see it used in a declaration, it's a type, and types should be capitalized. But when I try to capitalize it, Eclipse warns me that I shouldn't capitalize field names. I figure Eclipse probably knows the official Java conventions better than I do, but it just doesn't seem right. Even flipped through the Java conventions doc, but didn't see this issue referenced.

  • no pun intended

Solution

  • If they are their own class start with upper case, if they are members lower case.

    public enum ReportType { XML, TEXT, HTML };
    
    public class MyClass
    {
         ReportType defaultReport = ReportType.XML; 
    }