Details
-
Type:
Improvement
-
Status:
Closed
-
Priority:
Minor
-
Resolution: Fixed
-
Affects Version/s: 1.5.4
-
Fix Version/s: 1.7.9
-
Component/s: None
-
Labels:None
-
Environment:Mac OSX 10.4 Darwin 8.11.1, Groovy 1.5.4, Java 1.5.0_07
-
Testcase included:yes
-
Number of attachments :
Description
The following is listed in the usage guide as an example of adding a property to an existing class:
class Book {
String title
}
def properties = Collections.synchronizedMap([:])
Book.metaClass.setAuthor = { String value ->
properties[System.identityHashCode(delegate) + "author"] = value
}
Book.metaClass.getAuthor = {->
properties[System.identityHashCode(delegate) + "author"]
}
In other contexts, the -> is generally considered optional. However, if you do not use the -> list terminator in the get method closure, the read accessor does not work. For example, if you instead define getAuthor like:
Book.metaClass.getAuthor = {
properties[System.identityHashCode(delegate) + "author"]
}
the following occurs when you call the property accessor:
book = new Book() book.author = "foo" // works println book.author // does not work Caught: groovy.lang.MissingPropertyException: No such property: author for class: Book at Book.getProperty(propertyTest.groovy) at foo.run(propertyTest.groovy:15) at foo.main(propertyTest.groovy)
I'm new to Groovy and may very well be missing something, but this does not seem like expected behavior.
Activity
blackdrag blackdrag
made changes -
| Field | Original Value | New Value |
|---|---|---|
| Fix Version/s | 1.6-beta-1 [ 14008 ] | |
| Fix Version/s | 1.5.6 [ 14189 ] |
blackdrag blackdrag
made changes -
| Fix Version/s | 1.6-beta-1 [ 14008 ] | |
| Assignee | Jochen Theodorou [ blackdrag ] | |
| Fix Version/s | 1.5.6 [ 14189 ] |
blackdrag blackdrag
made changes -
| Priority | Major [ 3 ] | Minor [ 4 ] |
| Issue Type | Bug [ 1 ] | Improvement [ 4 ] |
| Fix Version/s | 1.6-beta-1 [ 14008 ] |
Guillaume Laforge
made changes -
| Fix Version/s | 1.6-beta-2 [ 14261 ] | |
| Fix Version/s | 1.6-beta-1 [ 14008 ] |
Guillaume Laforge
made changes -
| Fix Version/s | 1.6-rc-1 [ 14009 ] | |
| Fix Version/s | 1.6-beta-2 [ 14261 ] |
Guillaume Laforge
made changes -
| Fix Version/s | 1.5.8 [ 14630 ] | |
| Fix Version/s | 1.6-rc-1 [ 14009 ] |
Guillaume Laforge
made changes -
| Fix Version/s | 1.6.2 [ 15151 ] | |
| Fix Version/s | 1.5.8 [ 14630 ] |
Guillaume Laforge
made changes -
| Fix Version/s | 1.6.3 [ 15251 ] | |
| Fix Version/s | 1.6.2 [ 15151 ] |
Guillaume Laforge
made changes -
| Fix Version/s | 1.6.3 [ 15251 ] | |
| Fix Version/s | 1.7-beta-1 [ 14014 ] |
Guillaume Laforge
made changes -
| Fix Version/s | 1.7-beta-x [ 15538 ] | |
| Fix Version/s | 1.7-beta-1 [ 14014 ] |
Guillaume Laforge
made changes -
| Assignee | Jochen Theodorou [ blackdrag ] | Guillaume Laforge [ guillaume ] |
Guillaume Laforge
made changes -
| Status | Open [ 1 ] | Resolved [ 5 ] |
| Fix Version/s | 1.7.9 [ 17164 ] | |
| Fix Version/s | 1.7.x [ 15538 ] | |
| Resolution | Fixed [ 1 ] |
Paul King
made changes -
| Status | Resolved [ 5 ] | Closed [ 6 ] |
while -> might be optional in many cases it still has a meaning to use it or not to use it.So this is no error, but a RFE.