🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.language
Article #19995

Re: const in Java

#19995
From: Brian Burton
Date: Tue, 11 Nov 1997 00:00
43 lines
1995 bytes
Steve Demuth wrote:
> 
> Brian is correct that java has not const keyword, but incorrect that you
> can't accomplish
> 
>   void a(const char* a);
> 
> in java.  In fact, allowing for the difference between a char* and a String
> object,
> 
>   void a(String a)
> 
> does exactly that.  In java all arguments are passed by value (that is, as
> constant references, or "const p*".
> 
> Steve Demuth
> Artemis Alliance
> 

I treated his question as the more general one of "can I declare an object
passed as an argument to be "const" and unchangeable.  In that respect the
answer to his question is definitely "no".

Steve's answer is completely incorrect.  Object references passed into a method
are *not* const!  Not in any sense.  You can modify public members of the
objects and you can call methods on the arguments which modify the internal
state of the objects.

So the statement that passing an object reference p of class A to a method is
like using "const A *p" is flat out wrong.  It is actually like using "A &p", a
non-const reference to an object of class A.

I suggest that you refer to the Java language spec or read Java In A Nutshell. 
It contains a nice overview of the differences between Java and C++.

All the best,
++Brian

-- 
Brian Burton                        Custom Software Development
Burton Computer Corporation         Java, C++, Orbix, Tuxedo
http://www.burton-computer.com      OO Consulting and Mentoring
Technical Details
Message-ID: <3468B5A3.4CF924C4@burton-computer.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <3460FE29.6E0B0E7D@partal.com> <346207B2.3651FB01@burton-computer.com> <01bceecf$1dbb8200$cb00a8c0@pentpro5>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f74b3,281638c33db843f0
X-Google-Attributes: gidf74b3,public
From: Brian Burton <brian.burton@burton-computer.com>
Subject: Re: const in Java
Date: 1997/11/11
Message-ID: <3468B5A3.4CF924C4@burton-computer.com>
X-Deja-AN: 288693106
References: <3460FE29.6E0B0E7D@partal.com> <346207B2.3651FB01@burton-computer.com> <01bceecf$1dbb8200$cb00a8c0@pentpro5>
Organization: Burton Computer Corporation
Newsgroups: borland.public.jbuilder.java.language