jastrachan | 5 Apr 18:39 2004
Picon

Re: Properties


On 5 Apr 2004, at 17:28, Chris Poirier wrote:

> Hi all,
>
> Here's two cases for consideration:
>
> class MyClass
> {
>     int x;
>     int y = 0;
>
>     setX( int value )
>     {
>         x = value;
>         y++;
>     }
> }
>
> o = new MyClass()
> o.x = 10;
>
> What happens here?  If you have to think for even a second, there is
> something wrong.  Personally, I have to think for well over a second,
> and I'd have to write a test case or read the compiler code to be sure.

If the above class were written in Java code and the last 2 lines were 
groovy script the above would do what I thought it would without 
thinking particularly. Though I'm used to working with Java Beans so 
maybe thats just me.

> Counterpoint:
>
> class MyArray
> {
>     private int[] data = new int[] { 1, 2, 3 };
>
>     int getAt( int index )
>     {
>         return data[index];
>     }
> }
>
> o = new MyArray();
> x = o[1];
>
> Should that getAt() take a warning?  Or should it have property syntax,
> too?

I don't quite follow, operator overloading has nothing to do with Java 
Bean properties?

James
-------
http://radio.weblogs.com/0112098/

Gmane