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

  • SEARCH
  • Home
  • 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 6858733
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:11:46+00:00 2026-05-27T02:11:46+00:00

I have an enum with a nested enum (which I want to make private),

  • 0

I have an enum with a nested enum (which I want to make private), but when I do so GWT tells me that the nested enum is not visible and throws an exception.

public enum OuterEnum {
    A(NestedEnum.X),
    B(NestedEnum.Y),
    C(NestedEnum.X);

    NestedEnum nestedValue;
    private OuterEnum(NestedEnum nv) { nestedValue = nv; }

    private enum NestedEnum {
        X, Y;
    }
}

If I remove the private modifier from the nested enum then the code works. Why does GWT not allow the private modifier for nested enums? Is there a workaround?

  • 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-27T02:11:47+00:00Added an answer on May 27, 2026 at 2:11 am

    Serialization works just fine, at least with example you have provided. All enums a getting serialized/deserialized in following way(GWT 2.4, 2.3, 2.2):

        public static OuterEnum instantiate(SerializationStreamReader streamReader) throws SerializationException {
                int ordinal = streamReader.readInt();
                OuterEnum[] values = OuterEnum.values();
                assert (ordinal >= 0 && ordinal < values.length);
                return values[ordinal];
    }
    
        public static void serialize(SerializationStreamWriter streamWriter, OuterEnum instance) throws SerializationException {
                assert (instance != null);
                streamWriter.writeInt(instance.ordinal());
    }
    

    E.g. i doesn’t matter what is used inside. Only ordinal is passed over the network. It means there is a problem in some other place, GWT simply doesn’t care what is inside of enum, because it is not transferred over the network (enum’s should be immutable there is no need to transfer its state). I think your problem might be something like this:

    public class OuterClass implements Serializable{
    
        private OuterEnum.NestedEnum nested;
        private OuterEnum outer;
    
        public enum OuterEnum {
            A(NestedEnum.X), B(NestedEnum.Y), C(NestedEnum.X);
    
            NestedEnum nestedValue;
    
            private OuterEnum(NestedEnum nv) {
                nestedValue = nv;
            }
    
    
            private enum NestedEnum {
                X, Y;
            }
        }
    }
    

    This example is VERY different from previous one. Let’s assume that OuterClass is used in GWT-RPC service. Since NestedEnum used as field of OuterClass, GWT needs to create a TypeSerializer for it. But since a TypeSerializer is a separate class, it doesn’t have ANY access to the NestedEnum (since it is private). So the compilation fails.

    This basically the only case when your example will not work. There might be some bugs in some specific GWT versions, but i’m 100% sure that your example works in gwt 2.2-2.4 .

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

Sidebar

Related Questions

I have an enum which is private, not to be exposed outside of the
i have enum public enum TypeImage { Img=0, Thumb=1 } i want in view
I have an enum that looks as follows: public enum TransactionStatus { Open =
I have nested class public class Enums { public enum WindowModeEnum { Edit, New
I have enum list and method and i get error: not all code paths
I have an enum which is used by multiple classes. What is the best
I have an enum which is defined like this: public enum eRat { A
I have an enum that looks like the following: public enum EnumWeapons { Fists
I have an enum that I would like to randomly select a value from,
I have regularly wondered why C# has not yet implemeted a Generic Enum.Parse Lets

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.