Tommy
Reaction score
45

Joined
Last seen

Profile posts Latest activity Postings Trophies About

  • Thank you so much for this, really is appreciated & I find it very interesting.
    Hey,

    To answer your question, yes the naming of an enumeration element never changes. Enumeration elements are intended to be immutable and represent constant references to a single object. You can think of an enumeration like this;

    Code:
    static final class Food {
       
        public static final Food SHARK = new Food();
    
        private Food() {
    
        }
    }

    Which is exactly this

    Code:
    enum Food {
        SHARK
        ;
    
        private Food() { //private modifier is actually implicit and not needed to ensure
                                // an object cannot be constructed outside of the class
        }
    }

    The food object is immutable, and constant so therefor it follows the uppercase conventional naming.
  • Loading…
  • Loading…
  • Loading…
  • Loading…