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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T03:48:12+00:00 2026-06-10T03:48:12+00:00

Suppose I am writing a method foo(int i) in Java. Since i is passed

  • 0

Suppose I am writing a method foo(int i) in Java.
Since i is passed by value it is safe to change it in foo. For example

void foo(int i) {
   i = i + 1; // change i
   ...
}

Is it considered good or bad practice to change arguments of methods in Java?

  • 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-10T03:48:14+00:00Added an answer on June 10, 2026 at 3:48 am

    It’s considered bad practice in general, though some people overlook it as you can see in the other answers.

    For parameters like primitives that are directly passed in by value, there is no advantage in overriding the original variable. In this case you should make a copy as suggested by @João.

    For parameters whose reference is passed in by value (objects), if you modify the handle to point to a different object, that is downright confusing. It’s all the more important because modifying the contents of an object passed as a parameter will modify the original object too.

    If you replace the object referred to by the handle, and then modify its contents, the object referred to by the original reference in the caller will not be replaced, but someone reading the code might expect it to be.

    Whereas if you don’t replace the object, and modify the contents, the method calling your method might not expect this change. This category generally comes under security-related bad practices.

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

Sidebar

Related Questions

Let's suppose I have some method that returns a IEnumerable<int> object. This methods make
Given the following method: public static void SetPropertyValue(object target, string propName, object value) {
Suppose I have this interface public interface IFoo { ///<summary> /// Foo method ///</summary>
Suppose I have this class hierarchy: class A { public: virtual void foo(Base *b)
Suppose I'm writing a GUI class Kitteh (val age: Int) { require (age <
Suppose I have arbitrary template method, which could receive parameters by value and by
Suppose you're writing a simple database web application using Ruby and MySQL. Access to
Suppose I'm writing an SNMP v1/2 agent. Is it mandatory to append the instance
Suppose I'm writing a function that takes a list of integers and returns only
Suppose we are writing a class (let's call it Class) in an iPhone program.

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.