users
[Top] [All Lists]

Re: [cinjug-users] IDE Warning - Parameter value should not be assigned

To: esumerfd@xxxxxxxxxxxxxx
Subject: Re: [cinjug-users] IDE Warning - Parameter value should not be assigned
From: Rob Biedenharn <Rob_Biedenharn@xxxxxxxxxxxx>
Date: Wed, 2 Aug 2006 11:35:31 -0400
Cc: "users@xxxxxxxxxx" <users@xxxxxxxxxx>
Delivered-to: mailing list users@cinjug.org
In-reply-to: <6a216ba20608020750v496e606eh72da2bd5deb9f907@mail.gmail.com>
Mailing-list: contact users-help@cinjug.org; run by ezmlm
References: <6a216ba20608020750v496e606eh72da2bd5deb9f907@mail.gmail.com>
I think that occasionally it is the exact right thing to do when the alternative is to create a local variable to be initialized to the value of the parameter which you then manipulate.

The C/C++ issue is when you set the value by dereferencing a pointer passed as a parameter.  Often that meant setting array elements when receiving a pointer to the first element (and when strings are simply arrays of characters you start to see where the "problems" begin).

(but I've been Java-free for almost a year now, so feel free to ignore these comments ;-)

-Rob


On Aug 2, 2006, at 10:50 AM, Edward Sumerfield wrote:

Is the warning "The parameter value should not be assigned" still valid in Java?

    public void getFoo(int a_value, Object a_object)
    {
        a_value += 1;                     // WARNING
        a_object = new Object();     // WARNING
    }

It has always been good programming practice to avoid assigning parameters because in C/C++ you might be setting a pointer that the caller would not know had changed.

In java it is not possible set the object references that are passed in and the primitive types are passed by value so what is the danger?

I propose that the old bad practive rule be revoked in the light of better languages?

--
Ed

<Prev in Thread] Current Thread [Next in Thread>