On Thu, 14 Oct 1999 09:26:32 -0500 (CDT), Alex M. wrote:

>So there is no added benefit to declaring a parameter final other than to
>allow access from inner classes within the method.

Well, that is one benefit.  But the other benefit is a code maintainance
and readability issue.

By saying that a parameter is final you assure that no code within the
method will change that variable.  No, it does not make sure you do not
do methods on the object it may be a reference to but it does say you will
not change the reference.

For example:

        void foo(Object x)
        {
                //... do some stuff
                x=new Object();

                //... do some more stuff
        }

Sometimes this type of code is useful but sometimes it is just a bug
in thinking.  If you code the same thing with:

        void foo(final Object x)
        {
                //... do some stuff
                x=new Object();

                //... do some more stuff
        }

then the compiler will get upset since you can not change the value of
x.

Again, remember that there is a difference.  In fact, just like in C/C++,
a const pointer just means that it will not change what it points to and
not that what it points to will not be changed.

That is if char *x is a const pointer then it will always point to the
same memory location but the string at that location may change.  If
it is a pointer to a const, then the memory at that location will not
change but the location it points to may change.  In C/C++, if you want
both the point to be constant and what it points to be constant you
need a const pointer to a const char - aka "const char * const x"

-- 
Michael Sinz ---- Technology and Engineering Director/Consultant
"Starting Startups"                 mailto:[EMAIL PROTECTED]
My place on the web ---> http://www.users.fast.net/~michael_sinz



----------------------------------------------------------------------
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to