Bugs item #1708944, was opened at 2007-04-27 14:13
Message generated for change (Comment added) made by cgroves
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=112867&aid=1708944&group_id=12867
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: None
Group: None
>Status: Closed
>Resolution: Invalid
Priority: 5
Private: No
Submitted By: Philip Crotwell (crotwell)
Assigned to: Nobody/Anonymous (nobody)
Summary: overloaded setters in java not seen
Initial Comment:
public class StringBean {
String[] pod;
public String[] getPod() {
return pod;
}
public void setPod(String[] pod) {
this.pod = pod;
}
public void setPod(String pod) {
this.pod = new String[] {pod};
}
}
with the above class, this code fails in jython:
s = StringBean()
s.names='polebean'
with a can't convert String to String[] error:
TypeError: can't convert 'polebean' to [Ljava.lang.String;
Seems that jython should look for other "setters" that match the type of the RHS even if they take an argument of a different type from the getters return value.
Looking at the code, I think the problem steems from the fact that PyBeanProperty holds a single setter Method.
In PyType.fillInClassic(), the only methods that are searched for to put in the PyBeanProperty are ones with the correct name, ie setXYZ and with a single argument that is of the same type as the return of the getter. Any methods named correctly, setXYZ but with a different type in the argument are ignored.
In addition, if there is no getter, then the last setter to be found determines the bean params type. Probably would be better to not have a type if there are multiple setters but not a getter to specify it. Why would the last setter found be more important than the first one?
In some sense overloading setters isn't part of the real "javabean spec" but it seems a reasonible thing for java classes to do and would be nice if jython handled it.
----------------------------------------------------------------------
>Comment By: Charles Groves (cgroves)
Date: 2007-05-06 01:56
Message:
Logged In: YES
user_id=1174327
Originator: NO
The problem with this is that since it isn't a part of the javabean spec
there's no rule as far as pluralization of the setter name goes. In your
StringBean example, I would have named the methods getPods, setPods, and
setPod so your patch wouldn't match for single assignments. Naturally, we
could extend the patch to handle 'append an s' plurals, but then when my
bread management javabean has getLoaves, setLoaves and setLoaf and b.loaves
= 'pumpernickel' fails I'll be confused and hungry.
Putting a single item in a list and assigning it to an array javabean
works, so I don't think this is too big of a problem. ie
s = StringBean()
s.pods = ['polebean']
does what you'd expect it to.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=112867&aid=1708944&group_id=12867
|