Make Array Unmodifiable?

From: Ken (kk_oop_at_yahoo.com)
Date: 05/31/04


Date: 31 May 2004 05:50:40 -0700

Is there a standard approach or pattern for making an array that
cannot be modified? I ask this in this context: I'd like to be able
to return an array from a class method without letting the caller
subsequently modify the array. In C++ I'd return it as a const. Java
does not have such a construct. It seems that collections can handle
something like this, but then I lose the type safety of arrays.

Any suggestions?

Thanks,

Ken



Relevant Pages

  • Re: Why C Is Not My Favourite Programming Language
    ... And the number of modules in Python 2.4's Global Module Index is 362. ... The PDP architecture ideals ... fflushcan't be used to flush the contents of standard ... But it's not foolish that in ksh if you refer to an array name ...
    (comp.lang.c)
  • Re: "<>", a relational operator?
    ... And in Standard C there are significant restrictions ... OTOH in BCPL and B pointers were ... has no whole array operations; if you want something done to all (or ... the Standard isn't vague at all -- this is specifically ...
    (comp.lang.fortran)
  • Re: why cannot assign to function call
    ... hypothetical C-like languages, ... sizeof business would still indicate that a pointer was being passed. ... talk about variables of an array type. ... the earlier version of the standard didn't have numbered ...
    (comp.lang.python)
  • Re: Crazy stuff
    ... >>and the C standard states that it has the type array of char. ... C does not define "memory areas" at all. ...
    (comp.lang.c)
  • Re: Make Array Unmodifiable?
    ... > Is there a standard approach or pattern for making an array that ... HTH, ...
    (comp.lang.java.programmer)