Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6388893
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:20:10+00:00 2026-05-25T03:20:10+00:00

A coworker and I had a discussion about how Java represents enumerations. I was

  • 0

A coworker and I had a discussion about how Java represents enumerations. I was under the impression they were strictly ints like C/C++. Or, if you add behavior (Type-Safe enum), it gets wrapped in a class. He believed that if it’s small enough Java would compact it to a byte.

However, I found this on the Oracle site:

Java programming language enums are far more powerful than their counterparts in other languages, which are little more than glorified integers. The new enum declaration defines a full-fledged class (dubbed an enum type).

I take it they are actual objects then. If so, is there a way to optimize them to save space?

Thanks

Edit: As mentioned in a comment on Jon’s answer, I am after the serialization size of an Enum.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T03:20:11+00:00Added an answer on May 25, 2026 at 3:20 am

    No, Java enum values really are objects. They can have fields, methods etc – and different implementations of methods on a per-value basis. However, there’s only a fixed set of them – it’s not like you create instances of the enum type yourself; the set of valid values is created at type initialization time. Unless you’ve got a huge number of enum values, it’s highly unlikely you need to even think about optimizing.

    Note that one bit of optimization which is easy to achieve is using EnumSet whenever you’re logically considering a set of enum values. This uses a bit pattern to basically represent the set efficiently.

    (Note that C# is closer to C++ than Java here – the C# enums are sadly non-object-oriented. Sigh.)

    EDIT: Enum values are serialized by name according to the documentation:

    Support has been added to serialization to handle enumerated types, which are new in version 5.0. The rules for serializing an enum instance differ from those for serializing an “ordinary” serializable object: the serialized form of an enum instance consists only of its enum constant name, along with information identifying its base enum type. Deserialization behavior differs as well–the class information is used to find the appropriate enum class, and the Enum.valueOf method is called with that class and the received constant name in order to obtain the enum constant to return.

    If you’re really after a small serialized form though, you should probably steer clear of Java’s built-in serialization anyway, which is relatively verbose (as well as being extremely sensitive to versioning issues). There are all kinds of alternatives – the one I know best is Protocol Buffers, which does serialize enum values as just integers.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i had a discussion with a coworker about the architecture of a program i'm
A co-worker asked about some code like this that originally had templates in it.
I just had a discussion with a coworker concerning code in header files: He
Had a conversation with a coworker the other day about this. There's the obvious
I just had a discussion today with some coworkers about python's db-api fetchone vs
Today I had a coworker suggest I refactor my code to use a label
Had a coworker ask me this, and in my brain befuddled state I didn't
A coworker of mine has had issue with Mootools being backward compatible and I
My coworker is new to C# and didn't know about the coalesce operator. So,
I had some very wrong sounding advice recently from a senior developer/coworker regarding the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.