No way to specify that methods do not change the object on which they are invoked

10th February 2002

As we did in the previous commentary, let's start with the C++ binding, and its Connection class's Get Option method:

	const void *option (const char *key) const;
  

In C++, we can follow the declaration of a method with the keyword const to specify that the method does not change the state of its object when invoked. So far as I can tell, there is there no way to specify this in Java. A shame, since final (which in most contexts means pretty much the same as C/C++'s const) is available for this role.

Surely it can't be that the inventors of Java - a language in which interfaces play a crucial role - don't think that such elements of a method's contract are important?

Feedback to <mike@indexdata.com> is welcome!