

![]() | Start a set with this search |
![]() | Include this search in one of my sets |
![]() | Exclude this search from one of my sets |
![]() | Permalink to these results Paste this link in email or IM: |
| Atom feed for tracking future search results Paste this URL into your reader: |
15 messages in org.codehaus.groovy.userRe: [groovy-user] Setter overloading ...| From | Sent On | Attachments |
|---|---|---|
| Marc Palmer | Jun 4, 2008 7:08 am | |
| Jochen Theodorou | Jun 4, 2008 9:01 am | |
| Luke Daley | Jun 4, 2008 3:44 pm | |
| Marc Palmer | Jun 5, 2008 2:57 am | |
| Jochen Theodorou | Jun 5, 2008 3:32 am | |
| Jochen Theodorou | Jun 5, 2008 3:43 am | |
| Luke Daley | Jun 5, 2008 4:51 pm | |
| Danno Ferrin | Jun 5, 2008 6:24 pm | |
| Jochen Theodorou | Jun 5, 2008 7:12 pm | |
| Luke Daley | Jun 5, 2008 7:52 pm | |
| Luke Daley | Jun 5, 2008 8:48 pm | |
| Michael S. Jessop | Jun 5, 2008 9:49 pm | |
| Jochen Theodorou | Jun 6, 2008 4:03 am | |
| Danno Ferrin | Jun 6, 2008 5:25 am | |
| Danno Ferrin | Jun 6, 2008 5:28 am |

![]() | Permalink for this message Paste this link in email or IM: |
![]() | Permalink for this thread Paste this link in email or IM: |
| Atom feed for this thread Paste this URL into your reader: |
| Subject: | Re: [groovy-user] Setter overloading - should it work? | Actions... |
|---|---|---|
| From: | Marc Palmer (ma...@anyware.co.uk) | |
| Date: | Jun 5, 2008 2:57:16 am | |
| List: | org.codehaus.groovy.user | |
On 4 Jun 2008, at 23:44, Luke Daley wrote:
On 05/06/2008, at 2:02 AM, Jochen Theodorou wrote:
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.
It's not clear from your statements Jochen whether this is something that doesn't work now and may in the future, or for some technical reason can never work. In my opinion, this _is_ an issue as it is not what you would expect. It's reasonable to assume that setting a property like this would call the right setter. This assumption caused a bug for me that was very nasty and hard to track down.
Yes I suspected it was as Jochen said but you are right... I don't care what the bean spec says so much :) The fact that groovy turns x.duration = y into x.setDuration(y) for me means that Groovy should definitely use normal method resolution. Groovy goes much further than the bean spec already by providing this implicit property access.
It violates the principle of least surprise when you are coding with a Groovy head on. If you are coding with your Java beans oriented head on, it wouldn't seem like a problem.
If it's something that just doesn't work now please say so so a ticket can be raised.
I agree - is this technically feasible, if so can we JIRA it for 2.0?
Thanks Marc
--------------------------------------------------------------------- To unsubscribe from this list, please visit:







