No way to specify constant arguments

10th February 2002

In the C++ binding, we defined the Connection class's Get Option method as:

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

We marked the key string as const to reassure the caller that option() won't modify the pointed-to characters. (See the next commentary for my thoughts on the third const in this example.)

Since all objects in Java are passed by reference shouldn't we be able to specify something similar here? OK, as it happens, Java's String objects are immutable, so this particular problem doesn't arrise. But consider the ResultSet class's constructor, which takes a Query argument. What's to stop it from doing something evil like calling query.badgerUp() as a side-effect?

Nothing.

The stupidity of this is that you can declare the Java method as

	String option(final String key);
  
But that means something completely different. And not very useful.

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