Marc Palmer schrieb:
Hi,
Should setter overloading work?
I'm extending a java class that provides:
void setDuration(Duration d) { .. }
...in my groovy class extending it:
class EnhancediTunesEntryInformationImpl extends EntryInformationImpl {
void setDuration(String s) {
super.setDuration(new Duration(s))
}
}
...this fails with groovy complaining that it cannot cast the string to
Duration. If I change my setter to:
void setDurationText(String s) {
super.setDuration(new Duration(s))
}
it works fine.
So... should overloaded setters resolve with property access or not? I'm
just trying to establish whether or not there is a bug to isolate here.
The problem here is the bean specification. remember that when you do
foo.duration = "...", then you try to set a property named duration with
a string. Now the Bean spec knows only one setter and getter. And since
you do overload and not overwrite you end up with two of them. That's a
problem since Groovy expects, according to the spec, only of them. If
you do foo.setDuration(""), then there shouldn't be a problem at all.
bye blackdrag