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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T15:46:24+00:00 2026-06-06T15:46:24+00:00

The root of the problem for me is that Java does not allow references.

  • 0

The root of the problem for me is that Java does not allow references.

The problem can be summarized succinctly. Imagine you have a List of Blob objects:

class Blob {
    public int xpos;
    public int ypos;
    public int mass;
    public boolean dead;
    private List<Object> giganticData;
    public void blobMerge(Blob aBlob) {
        . . .
        if (. . .) {
            this.dead = true;
        } else {
            aBlob.dead = true;
        }
    }
}

If two blobs are close enough, they should be merged, meaning one of the two blobs being compared should take on the attributes of the other (in this case, adding the mass and merging the giganticData sets) and the other should be marked for deletion from the list.

Setting aside the problem of how to optimally identify adjacent blobs, a stackoverflow question in its own right, how do you keep the blobMerge() logic in the Blob class? In C or C++ this would be straightforward, as you could just pass one Blob a pointer to the other and the “host” could do anything it likes to the “guest”.

However, blobMerge() as implemented above in Java will operate on a copy of the “guest” Blob, which has two problems. 1) There is no need to incur the heavy cost of copying giganticData, and 2) the original copy of the “guest” Blob will remain unaffected in the containing list.

I can only see two ways to do this:

1) Pass the copies in, doing everything twice. In other words, Blob A hosts Blob B and Blob B hosts Blob A. You end up with the right answer, but have done way more work than necessary.

2) Put the blobMerge() logic in the Class that contains the containing List. However, this approach scales very poorly when you start subclassing Blob (BlueBlob, RedBlob, GreenBlob, etc.) such that the merge logic is different for every permutation. You end up with most of the subclass-specific code in the generic container that holds the list.

I’ve seen something about adding References to Java with a library, but the idea that you have to use a library to use a Reference put me off that idea.

  • 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-06T15:46:25+00:00Added an answer on June 6, 2026 at 3:46 pm

    Why would it operate on a copy? Java passes references to objects. And references are very much like C++ pointers.

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

Sidebar

Related Questions

I have written a code that does SSH in servers and runs a Java
I have some Java code that determines the namespace of the root-level element of
My root problem is that when using calls Dispose on a StreamWriter , it
The problem is that /var/run/netns/ directory contains all the network namespaces, except the root
I have a problem with the MySQL root user in My MySQL setup, and
I have currently the following problem. I have a directory structure like root -
So I have a java class that takes individual commands and puts them into
I have the following problem. I programmed a java servlet, which responses to ajax
[Meta notes: the following question is not answered, but the problem that the question
I have a multi module Spring project that I set up using Maven: my-root

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.