Friday, January 26, 2007

When is a property not a property?

There's a lot of talk about property support in Java 7. Some of the proposals allow you (like C#) to access the get/set methods without using the method name: //actually calls Foo.getBar() or a reasonable facsimile

Except now you've made a distinction between accessing it as a 'property' and accessing it via a method. What's the difference? Richard Blair says "read the docs", but I think that's the wrong answer. The language has made a distinction by allowing two ways to access code that makes multiple modifications to an object's state. If the distinction is meaningless, then it adds clutter. Any access to a 'property' needs to appear to be a method call to client code, because that sets expectations accordingly.