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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:08:42+00:00 2026-05-25T20:08:42+00:00

If Java is strictly pass-by-value for non primitive, isn’t it better to establish coding

  • 0

If Java is strictly pass-by-value for non primitive, isn’t it better to establish coding standards like make all formal parameters of methods and constructors final? – to avoid confusion?

  • 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-05-25T20:08:42+00:00Added an answer on May 25, 2026 at 8:08 pm

    If Java is strictly pass-by-value for non primitive

    Java is strictly pass-by-value for ALL arguments and ALL results, irrespective of type.

    And if you don’t understand, or don’t believe me, read Java is Pass-by-Value, Dammit!

    … can I mandate a final modifier in formal parameters?

    Yes you could, but it would be a bad idea to do it for the reasons that you have given.

    Declaring a method or constructor’s formal parameters to be final means something different to the meaning that you are trying to place on it. Specifically, it means that the parameter can’t be assigned to in the body of the method / constructor.

    Doing this has the following consequences:

    • It will actually change the meaning of the code in a way that could cause compilation errors in some cases. (These are good compilation errors … because they force the programmer to stop doing something that generally makes his code less clear. But fixing takes effort and requires retesting, etc.)

    • Seasoned Java programmers are not going to read into this the meaning that you intend. (Not that they should need to be reminded …).

    • Novice Java programmers are likely to be more confused … especially if they pick up the incorrect notion that declaring something to be final alters the argument passing semantics!

    So this does not achieve your aim.

    The real solution is to educate people that Java ALWAYS uses pass-by-value. (And that includes beating up people who persist in spreading false information and doubt about this … like your question does!)


    (In nearly all cases, it is good practice to not update formal parameters, and declaring them final prevents you doing this by accident. So this is good practice. But the reason it is good practice is not what you stated … and if you did put this into a coding standard with the reasoning that you gave, you would deserve to be roundly criticised.)

    And if you don’t understand, or don’t believe me, read Java is Pass-by-Value, Dammit!

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

Sidebar

Related Questions

I read this excellent article and it make sense: Java is strictly pass by
JavaScript is non-strictly typed language as Java,for example. As we know, it converts value
First of all, I know how to build a Java application. But I have
Support I have a Java Bean class that strictly holds instance fields: class College
I would like to create Java applications, but my first brake is that it
As I'm sure you all know Java enforces a very strict pattern for error
In Java 6, is it possible to inject some value into a ( @Target(ElementType.PARAMETER)
Java has generics and C++ provides a very strong programming model with template s.
Java has a convenient split method: String str = The quick brown fox; String[]
(Java question) If I reference a field in an inner class, does this cause

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.