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 3432616
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T07:28:16+00:00 2026-05-18T07:28:16+00:00

I’ve noticed enums introduce many additional class files (Class$1) after compilation bloating the total

  • 0

I’ve noticed enums introduce many additional class files (Class$1) after compilation bloating the total size. It seems to be attached to every class that even uses an enum, and these are often duplicated.

Why does this occur and is there a way to prevent this without removing the enum.

(Reason for question is space is at a premium for me)

EDIT

On investigating the issue further, Sun’s Javac 1.6 creates an additional synthetic class each time you use a switch on an Enum. It uses some kind of SwitchMap. This site has some more information, and here tells you how to analyse what Javac is doing.

An additional physical file seems a high price to pay each time you use a switch on an enum!

Interestingly, Eclipe’s compiler does not produce these additional files. I wonder if the only solution is to switch compilers?

  • 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-18T07:28:17+00:00Added an answer on May 18, 2026 at 7:28 am

    I was just bit by this behavior and this question showed up when Googling. I thought I’d share the little bit of extra information I found out.

    javac 1.5 and 1.6 create an additional synthetic class each time you use a switch on an enum. The class contains a so-called “switch map” which maps enum indices to switch table jump numbers. Importantly, the synthetic class is created for the class in which the switch occurs, not the enum class.

    Here’s an example of what gets generated:

    EnumClass.java

    public enum EnumClass { VALUE1, VALUE2, VALUE3 }
    

    EnumUser.java

    public class EnumUser {
        public String getName(EnumClass value) {
            switch (value) {
                case VALUE1: return "value 1";
                // No VALUE2 case.
                case VALUE3: return "value 3";
                default:     return "other";
            }
        }
    }
    

    Synthetic EnumUser$1.class

    class EnumUser$1 {
        static final int[] $SwitchMap$EnumClass = new int[EnumClass.values().length];
    
        static {
            $SwitchMap$EnumClass[EnumClass.VALUE1.ordinal()] = 1;
            $SwitchMap$EnumClass[EnumClass.VALUE3.ordinal()] = 2;
        };
    }
    

    This switch map is then used to generate an index for a lookupswitch or tableswitch JVM instruction. It converts each enum value into a corresponding index from 1 to [number of switch cases].

    EnumUser.class

    public java.lang.String getName(EnumClass);
      Code:
       0:   getstatic       #2; //Field EnumUser$1.$SwitchMap$EnumClass:[I
       3:   aload_1
       4:   invokevirtual   #3; //Method EnumClass.ordinal:()I
       7:   iaload
       8:   lookupswitch{ //2
                    1: 36;
                    2: 39;
                    default: 42 }
       36:  ldc     #4; //String value 1
       38:  areturn
       39:  ldc     #5; //String value 3
       41:  areturn
       42:  ldc     #6; //String other
       44:  areturn
    

    tableswitch is used if there are three or more switch cases as it performs a more efficient constant-time lookup vs. lookupswitch‘s linear search. Technically speaking javac could omit this whole business with the synthetic switch map when it uses lookupswitch.

    Speculation: I don’t have Eclipse’s compiler on hand to test with but I imagine that it doesn’t bother with a synthetic class and simply uses lookupswitch. Or perhaps it requires more switch cases than the original asker tested with before it “ugprades” to tableswitch.

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

Sidebar

Related Questions

No related questions found

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.