Hi Robert,
Adding the final keyword to a variable in an argument list only
means that the reference is final, ie you can't make the reference refer to
another object. I does not mean that I can't call certain methods in the
same way as C++.
Regards
--Jools
>From: "Robert Simmons" <[EMAIL PROTECTED]>
>To: <[EMAIL PROTECTED]>
>Subject: Const in java
>Date: Wed, 13 Oct 1999 15:54:26 -0600
>
>I was always the real proponent of type and instance safety in c++. for
>example.
>
>class Foo {
> private BarClass _bar;
>
> public const BarClass& getBar();
> public setBar(const BarClass const &bar);
>}
>
>This snippet guarantees that someone doesnt pull a getBar() then set the
>return result. ie:
>
>void main {
> Foo f = new Foo();
> BarClass c = new BarClass();
> BarClass b = g.getBar();
> b = c; // DOH we just changed bar inside of the f instance
>}
>
>Also it guarantees the following cant happen:
>
>Foo::setBar(const BarClass const &bar) {
> bar = new BarClass(); // DOH, just overwrote the var outside the method
>}
>
>Since everything in java is passed by reference this becomes even more of
>an issue.
>Therefore can I do the following to achieve the desired safety ?
>
>class Foo {
> private BarClass _bar;
>
> public final BarClass& getBar();
> public setBar(final BarClass bar);
>}
>
>Thanks for your time.
>
>--rob
______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com
----------------------------------------------------------------------
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]