Re: How do java programmers cope with java missing c++ const?
- From: Dimitri Maziuk <dima@xxxxxxxxx>
- Date: Tue, 28 Feb 2006 17:34:13 +0000 (UTC)
Michael Redlich sez:
....
josh.s17@xxxxxxxxx wrote:
I've been working with java for a while now, but I miss the ability to
pass around objects that can't be modified, as is possible with the c++
const keyword. Is it just me or do others find this a limitation of
java? I've read the way to do it in java is to pass around immutable
objects however that seems a lot less flexible than having the ability
to pass a const reference to a mutable object as can be done in c++.
In any event, you could do similar things in Java using the 'final'
keyword. It is a modifier used to change the characteristics to
classes, methods, field, and parameters so that those items cannot be
changed.
Except of course if the parameter is an object, it is actually
a pointer. So 1) final'ing the pointer does not prevent changes
to the actual object, and 2) since pointer is passed by value,
changing it does not change the object, and any such change is
lost upon exit from subroutine. IOW, it isn't clear exactly
what the point of declaring parameters "final" is: it doesn't
do anything actually useful.
Dima
--
Sufficiently advanced incompetence is indistinguishable from malice.
.
- References:
- How do java programmers cope with java missing c++ const?
- From: josh . s17
- Re: How do java programmers cope with java missing c++ const?
- From: Michael Redlich
- How do java programmers cope with java missing c++ const?
- Prev by Date: Re: a question relating to job application
- Next by Date: Re: How large is an object reference?
- Previous by thread: Re: How do java programmers cope with java missing c++ const?
- Next by thread: Re: How do java programmers cope with java missing c++ const?
- Index(es):
Relevant Pages
|