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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:59:48+00:00 2026-06-13T05:59:48+00:00

I am a little confused with Java All passings by value concept. Consider the

  • 0

I am a little confused with Java “All passings by value” concept.

Consider the following code:

class Test {
    Integer A;
    String B;
    ...

    void SetVar(Object??? var, Object value) {
        // Set A variable to the value (considering that it's possible)
    }
}

can I code the SetVar function in the way that the following code sets A to 2 and B to Hi??

void Init() {
    SetVar(this.A, 2);
    SetVar(this.B, "Hi");
}
  • 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-13T05:59:50+00:00Added an answer on June 13, 2026 at 5:59 am

    To put it in a nutshell, reassigning a value (meaning with = operator) to an existing reference does not change the object pointing by the original reference.

    A big misunderstood in Java is that folks think that they are two types of variables:

    • Primitives (like int, boolean etc…)
    • References (like Integer, Boolean, custom objects etc…)

    Java NEVER uses references. The word Reference is misnomer.

    Java only uses Pointers instead for manipulating objects.

    To better understand the shade: http://javadude.com/articles/passbyvalue.htm

    Regarding your case, even though you skipped the Java Naming Conventions (but it’s another subject), you could solve your “issue” by doing:

    void SetVar(Integer value) {
            this.A = value;
    }
    

    Indeed, if you pass A as a local parameter (as you did), this local parameter will represent a copy of the A reference since Java is only focused on passed-by-value. So changing it does not affect the initial reference.

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

Sidebar

Related Questions

I'm a little confused of the handling between the java Date Class and GregorianCalendar
I'm a little confused about iterators in Java. How do I make next() only
I am a little confused about the roles of a java application server and
I am trying to profile my java application with JProbe. I am little confused
I'm a little confused by the structure of the Node class in OpenJDK's implementation
I just started exploring Java Servlets and JSP and am a little confused about
I'm learning C# and coming from a Java world, I was a little confused
I've been looking through some production code, and I'm a little confused on the
I'm still a little new to Java, and I'm quite confused with how objects
I'm a little confused by the difference between Java and Android Java. Let's say

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.