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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T18:16:05+00:00 2026-06-12T18:16:05+00:00

public class TopLevelObject{ List<SecondLevelObject> secondLevelObjects; Long field; } public class SecondLevelObject{ List<ThirdLevelObject> thirdLevelObjects; Long

  • 0
 public class TopLevelObject{

    List<SecondLevelObject> secondLevelObjects;
    Long field;

}

public class SecondLevelObject{
    List<ThirdLevelObject> thirdLevelObjects;
    Long field;

}

public class ThirdLevelObject{
     Long field1;
     Long field2;

}

We have a TopLevelObject, which contains a list of SecondLevelObjects, all of which contain list of ThirdLevelObjects

We need to initialize some fields of this structure initially by iterating through it, and postpone initializing the others, but avoid iterating it all over again

So is it possible to store references/path to the setters of that field to call them later? (Assuming you can know which setter to call when)

  • 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-12T18:16:06+00:00Added an answer on June 12, 2026 at 6:16 pm

    Firstly, is this just a matter of performance? Because if so, come back when you’ve measured it.

    Second, check you’re not being too clever. Read up about the Inner Platform effect. Do you really need to hand-roll this lazy initialization code, or can you use JPA or something else?

    If you’re still sure, you can use a custom object that defers the setting like this

    // [some code that is about to set the property on thirdLevelObject
    Runnable deferredSetter = new Runnable() {
        public void run() {
             thirdLevelObject.setFoo(/* wherever the value for foo comes from later */);
        }
    } 
    

    These deferred setter Runnables can be added to a collection that you would loop through during the later initialization. But I still think you can avoid this approach by simplifying your design.

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

Sidebar

Related Questions

public class Knowing { static final long tooth = 343L; static long doIT(long tooth)
public class User { public long Id {get;set;} [References(typeof(City))] public long CityId {get;set;} [????]
public class ClassScanner { // scan extraClasspath for specific classes public List<Class<?>> scanClasspathForClass(String scanCriteria)
public class Emp { Integer eid; String ename; long sal; Dept dept; } public
public class abc<X extends Z> implements Iterable<X> { protected ArrayList<X> list; public Iterator<X> iterator()
public class Parent { public virtual long Id { get; set; } public virtual
Public Class EquipmentCollection { Public Property EquipmentList As List(Of Equipment) } Public Class Equipment
public class Item { ... } public class Order { public List<Item> Items ...
public class readBin { public static void main(String[] args) throws IOException{ long time1 =
public class SuperUser extends User implements Serializable{ private static final long serialVersionUID = 1L;

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.