Re: How do java programmers cope with java missing c++ const?



Michael Redlich wrote:
* A field (class or instance) that is declared 'final' cannot be
modified and must be initialized at the point of declaration.

That's not true, or even normal for instance fields.

Final instance fields must be definitely assigned (see the whole chapter on definite assignment in the JLS) in every constructor (where each constructor includes any initialisers). Local final variables are much the same (only they don't have to be assigned if unused and can't be seen by devious means before initialisation).

Tom Hawtin
--
Unemployed English Java programmer
http://jroller.com/page/tackline/
.



Relevant Pages

  • Re: Controlled types and exception safety
    ... >> constructor throws/raises, the object is considered to be never created ... you'll have memory leaks and other such badness. ... > actually wish is to have access to the left side of assignment. ... Ada doesn't really have user-defined assignment; ...
    (comp.lang.ada)
  • Re: Ada Interfaces and the Liskov Substitution Principle
    ... You don't have to do anything to make assignment for access T'Class ... There is the tag, it exists before the object and comes from the type of. ... Following your argument destructor of X isn't dispatching either, ... A part of the constructor of T'Class is certainly dispatching. ...
    (comp.lang.ada)
  • Re: Copy Constructors and Assignment Operator, When should I use?
    ... ItemSet set1; ... constructor for ItemSet, ItemListA and ItemListB for it works ... plain reference. ... using assignment instead of initialisation), so there is no need to write ...
    (microsoft.public.vc.language)
  • Re: operator=
    ... Compiler will supply - unless the programmer decides to do it - the ... It isn't required in an assignment: ... You will find that the code within the copy constructor and assignment ... Aside from the inlined code [i.e. the member ...
    (alt.comp.lang.learn.c-cpp)
  • Re: memcpy and STL vector
    ... what it calls POD types. ... The copy constructor is called in a copy by value parameter passing. ... What's the default behavior for assignment then if assignment is not ... then each of the data members in turn. ...
    (comp.lang.cpp)