Small property support.
David Goodenough
david.goodenough at linkchoose.co.uk
Wed Mar 18 07:46:49 PDT 2009
On Wednesday 18 March 2009, Ruslan wrote:
> Hello.
>
> David Goodenough wrote:
> > On Wednesday 18 March 2009, Ruslan wrote:
> >> Hello.
> >>
> >> Yes, i have read it.
> >> But we are trying to fix different things:
> >> - You are trying to get rid of strings in "Beans Binding of JPA Criteria
> >> API"
> >
> > As a matter of interest, how would I pass a property reference using
> > your proposal?
>
> My proposal have another goal. Goal is to have synthetic sugar like
> for-each for property.
> And in my case there is not property reference, so you can not pass it.
>
> Property references can be added at next release (5 years later ;) ).
>
> >> - And my point is to make property code readable and get rid of
> >> getters/setters when use Dependency Injection.
> >
> > For simple getters and setters, my proposal does actually get rid of
> > getters and setters, in that the Property object will do the work for you
> > using the Field get and set (and some snake oil to handle
> > PropertyChangeSupport).
>
> Yes, that is true. And my proposal are not using Property or Field. It's
> like macros for property get/set generation.
>
> > David
>
> PS my goal is to avoid situation like this:
> private int i;
>
> public String getI() {
> return Integer.toString(i);
> }
>
> public void setI(long i) {
> this.i = (int)i;
> }
>
> What is the type of property 'i' ?
>
> private int i;
>
> public int getJ() {
> return i;
> }
>
> public void setI(int i) {
> this.i = i;
> }
>
> IS everyone see that there is not getter for 'i' - we have getter for
> 'j'. But compiler will not fix this error, because it is a logical
> error, not language.
>
>
> Ruslan.
In my proposal all you have to do is to declare i, and I will provide you
with getter and setter access to it through the Property object.
So you would have:-
class Foo {
private int i;
}
...
Property<Foo,Integer>propI = foo#i;
propI.set(6);
and if Foo had a PropertyChangeSupport object as a field, it would fire
the correct PropertyChangeEvent as well.
It is of course entirely compiler checkable.
David
More information about the coin-dev
mailing list