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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T00:51:16+00:00 2026-06-06T00:51:16+00:00

Okay this is definitely a n00b question but here goes. The way I understand

  • 0

Okay this is definitely a n00b question but here goes.

The way I understand it, is objects in Java are passed by value, not reference. How then do you alter a class member within a method by passing a reference to it to the method?

I know it is possible to do, because the method getRotationMatrix does it… ie if I write the following at the class level:

private float rotationMatrix[] = new float[9];

and then within a method I call:

SensorManager.getRotationMatrix(rotationMatrix, inclinationMatrix, gData, mData);

It will alter rotationMatrix. My question is how does that method change what is in the object I passed it if everything is passed by value?

The reason I ask is I am trying to write a method that does the same thing, but keep running into the pass-by-value conundrum. I’m trying to initialize a FloatBuffer by passing a reference to it to a method.

  • 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-06T00:51:18+00:00Added an answer on June 6, 2026 at 12:51 am

    Yes objects are passed by value. But the Object is a reference so a copy of reference is passed. Using the reference you can modify the object but changing the reference will not have any effect on caller.

    For example:

    List list = new ArrayList();
    modifyList(list);
    noOp(list);
    
    void modifyList(List l)
    {
       l.add("A"); // A is added to list
    }
    
    void noOp(List l)
    {
       l = null; // No effect to list, you are modifying local variable l.
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay this is definitley an easy question and a stupid one but since I
Okay this may be a simple question but I have yet to come with
Okay this is not a question of how to get all uniques or How
1. Okay this is probably lame question, but I haven't found good result searching
Okay this is similar to my last question but what I ended up doing
Okay this question is very simple: I have a facebook page, and a website.
Okay this is my 4th question today on Scheme, still pretty new to Scheme,
Okay this is probably a really dumb question, however it's really starting to hurt.
Okay this is very hard to explain, but i want to add padding to
Okay this may sound a bit weird but it is what I have to

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.