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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T15:51:21+00:00 2026-06-04T15:51:21+00:00

Is it possible to serialize a non Static Inner class? If yes can you

  • 0

Is it possible to serialize a non Static Inner class?

If yes can you provide a good example.

I googled through few blogs and sites non of answer convinced me.

EDIT:
How about the inner class having final staic variable.

  • 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-06-04T15:51:23+00:00Added an answer on June 4, 2026 at 3:51 pm

    Inner class contains an implicit reference to the outer class, so for
    an inner class to be serializable its outer class must be as well.

    Exactly from docs:

    Serialization of inner classes (i.e., nested classes that are not
    static member classes), including local and anonymous classes, is
    strongly discouraged for several reasons. Because inner classes
    declared in non-static contexts contain implicit non-transient
    references to enclosing class instances, serializing such an inner
    class instance will result in serialization of its associated outer
    class instance as well. Synthetic fields generated by javac (or other
    JavaTM compilers) to implement inner classes are implementation
    dependent and may vary between compilers; differences in such fields
    can disrupt compatibility as well as result in conflicting default
    serialVersionUID values. The names assigned to local and anonymous
    inner classes are also implementation dependent and may differ between
    compilers. Since inner classes cannot declare static members other
    than compile-time constant fields, they cannot use the
    serialPersistentFields mechanism to designate serializable fields.
    Finally, because inner classes associated with outer instances do not
    have zero-argument constructors (constructors of such inner classes
    implicitly accept the enclosing instance as a prepended parameter),
    they cannot implement Externalizable. None of the issues listed above,
    however, apply to static member classes.

    So

    Because inner classes declared in non-static contexts contain implicit
    non-transient references to enclosing class instances, serializing
    such an inner class instance will result in serialization of its
    associated outer class instance as well.

    Source

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

Sidebar

Related Questions

Is it possible to non intrusively serialize a class with private data but with
It is possible to serialize only a few properties of the class? ex: public
Possible Duplicate: How to serialize an IList<T>? I wish to serialize an class (let's
Is it possible to serialize a method containing yield statements (or a class that
To Serialize a class with protobuf-net, you neet to provide the class and property
is it possible to serialize object like this , with const property? class A
Is it possible to serialize or deserialize any pointer? Suppose I have a class
How is it possible to serialize sub-objects to $_SESSION? Here is an example of
Is it possible to serialize and deserialize a class in C++? I've been using
I want to serialize an instance of FtpWebRequest class. Is it possible? When i

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.