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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T08:07:31+00:00 2026-06-02T08:07:31+00:00

I have a saving/loading framework that is supposed to save arbitrary object graphs. This

  • 0

I have a saving/loading framework that is supposed to save arbitrary object graphs. This includes instances of non-static nested classes.

Nested classes require are owned by the instance of their parent class that created them, and the nested class knows what instance it belongs to using a synthetic field.

As a simple example, I present this class:

public class Foo implements Savable {
  private class Bar implements Savable {
    public void saveState(Saver saver) {
      saver.putInt(3);
    }
  }
  private Bar myBar = new Bar();
  public void saveState(Saver saver) {
    saver.putSavable(myBar);
  }
}

On the “standard” compiler, the following code works just fine to take in an object (myBar), find its parent (a particular instance of Foo), and keep a reference of it with the child:

if (objectClass.isMemberClass()) {
  //We are a member class, which means we are a non-static inner class, and therefore must save our parent.
  Field[] fields = objectClass.getDeclaredFields();
  //We loop through each of our fields to find the synthetic field created by the compiler that points to our parent.
  for (Field f : fields) {
    String name = f.getName();
    //The synthetic field pointing to the parent is named something like "this$0".  At least, with the "standard" compiler it is.
    if (name.startsWith("this$")) {
      f.setAccessible(true);
      Savable parent = (Savable)f.get(objectClass);
      saver.putSavable("_parent", parent);
      break;
    }
  }
  if (!saver.containsKey("_parent")) {
    throw new RuntimeException("Could not find the owner of inner class: " + objectClass);
  }
}

So, like I said, this works just fine in on the “standard” compiler. Then at load time, something similar happens, except I look for a constructor that takes in an instance of the parent class and instantiate it, passing in the parent.

But!

It doesn’t work on the Android VM. There are no synthetic fields, and the constructors all look normal, like they don’t take in a parent instance.

Am I SOL here? This VM obviously does not like my approach. Is there anything I can do here without requiring inner classes to know that they need to save a reference to their parent class instance?

  • 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-02T08:07:32+00:00Added an answer on June 2, 2026 at 8:07 am

    Okay, turns out I was barking up the wrong tree. The method I’ve outlined works perfectly well on Android just as well as anywhere else. The problem was that the class I was trying to instantiate in this case was a static internal class. So, while it was a member class, it didn’t have a reference to its outer class. I just have to check if (!Modifier.isStatic(objectClass.getModifiers())) before looking for a synthetic constructor/field.

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

Sidebar

Related Questions

I have been working on saving/loading, and I came across that I have to
I am using CakePHP framework with MySQL database and I have problem in saving
I have a dynamically created image that I am saving to a stream so
I have a small question. I'm writing a loading/saving function for getting plain geometry
Is there a pattern that is good to use when saving and loading different
Hi I have a problem saving 2 tables of my database at the same
I have ListView which is saving all data to database. For adding i have
We have a weird intermittent problem with saving from Word 2007 to our SharePoint
I have seen two different approaches in saving user preferences. APPROACH 1: Serializing them
I have a ZF app and am saving times as UTC in MySQL db.

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.