Sunday, December 20, 2009

Alternative to Getter/Setters Contd...

Looks like my last blog on this subject got some attention in dzone. It was pleasing to see those up votes. There were some down votes as well. I am trying to figure out why there were so many down votes. Probably they did not like the idea that a private field which have getter/setter can be treated just like a public field. Although essentially it is public but idea that you could directly access and change the field without going to through the getter/setters is not palatable to lot of people. If it walks like duck, quacks like duck, sometimes it is really not a duck! Some people pointed out getter/setters could be quite different from [return field;] and [this.field = field;] kind of code. In that case, one could provide explicit getter/setters. The annotation model will only apply to the most common case. In the lombok project also, this is the case the annotation will cover. Even then, I do not think java community, in general, will like the idea to treat private fields as public fields.

This was the idea my last blog that I was trying to push. Most of the other ideas presented have already been featured in the lombok project. Although it is not fashionable now, it might become in future.

What is not yet implemented in the lombok project is the Constructor annotation. This will really save lot of code clutter. This constructor annotation could have optional parameters to call super(), or some other method. e.g. init(), etc. If anyone has any comments or suggestions please post below.

1 comment:

Anonymous said...

getter/setter is availble for lazy load or set, see erlang.