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

Reply via email to