You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@groovy.apache.org by Schalk Cronjé <ys...@gmail.com> on 2015/11/23 15:29:31 UTC
Comparing closures
I ran into this little problem whilst working on the groovy-vfs plugin
for Gradle.
The plugin has a map that gets serialized (as per what Gradle does with
task attributes). I can simplify it to this bit of Groovy.
class Task {
// it does not matter what the content of the closure is; it is
always the same
final static def clo = { }
@Input // <-- That is just a Gradle annotation
Map getMap1() {
[ overwrite : clo, recursive : true ]
}
}
The problem lies herein that when getMap1 is serialized and subsequently
deserialized, the deserialized map is not equivalent of the original
map1. Essentialy the equivalent of the following code
def m1 = [ a : {} ]
def m2 = [ a : {} ]
assert m1 == m2 // fails
Obviously what I am seeing is not unique to Gradle. I can understand at
a high level why it is happening, but I was wonder if there is some
other way to achieve the result of comparing two closures for some form
of equivalence.
--
Schalk W. Cronjé
Twitter / Ello / Toeter : @ysb33r