> About the only thing in the series that really had me in > disagreement with Anders was his remarks about 'const'. > > [Stuff deleted] > > Back in my main C++ days (most of my programming these > days is in perl doing network admin automation and > internal tools since my company went Java and I can't > stand java :)) we used const quite effectively to provide > a good semantic communication to people writing code.
The standard method in Java is to define a class with a constant interface, get methods and **no** set methods, then to derive a class from it with the set methods. This behaves just like const in C++.
The problem, as in C++, is that the above const/mutable classes can't be compiler enforced, only enforced at runtime. IE you can cast away const delibrately or accidently! A further issue is that you often need to repeat methods, e.g. a max method that returns a const for consts and a max method that returns a mutable for mutables. I think this is what Anders Hejlsberg was getting at and is the big difference between final in Java and const in C++.