Groovy的wIndeed。我仍然不完全确定那里发生了什么。 def x = 2 x << 2 //x == 8 "${ w -> w << 3}" //w == 3 def transform(List elements, Closure action) { def result = [] elements.each { result << action(it) } result } def x = 2 assert x << 2 == 8 assert "${ w -> w << 3}" == '3' def transform(List elements, Closure action) { def result = [] elements.each { result << action(it) } result } class Lol { def leftShift(o) { println o } } new Lol() << 'string' //prints 'string'

Groovy的wIndeed。我仍然不完全确定那里发生了什么。 def x = 2 x << 2 //x == 8 "${ w -> w << 3}" //w == 3 def transform(List elements, Closure action) { def result = [] elements.each { result << action(it) } result } def x = 2 assert x << 2 == 8 assert "${ w -> w << 3}" == '3' def transform(List elements, Closure action) { def result = [] elements.each { result << action(it) } result } class Lol { def leftShift(o) { println o } } new Lol() << 'string' //prints 'string',groovy,bitwise-operators,Groovy,Bitwise Operators,我是Groovy新手,对于Groovy中的,Groovy中的,你的转换可以写成元素;快速规则:无论何时你看到x,我都能理解为什么它可能有点混乱,但它确实是有意义的。想一想,谢谢大家在这里的评论。所有这些答案都很有帮助。我仍然担心你能做到这一点,但至少你的评论似乎说明了我应该如何看待它。就像+运算符对不同类型有不同的影响一样,你的转换也可以写成元素。收集{actionit},这样就不会那么混乱;快速规则:无论何时你看到x,我都能理解为什么它可能有点混乱,但它确实是有意义的。想一想,谢谢大家在这里的

我是Groovy新手,对于Groovy中的,Groovy中的,你的转换可以写成元素;快速规则:无论何时你看到x,我都能理解为什么它可能有点混乱,但它确实是有意义的。想一想,谢谢大家在这里的评论。所有这些答案都很有帮助。我仍然担心你能做到这一点,但至少你的评论似乎说明了我应该如何看待它。就像+运算符对不同类型有不同的影响一样,你的转换也可以写成元素。收集{actionit},这样就不会那么混乱;快速规则:无论何时你看到x,我都能理解为什么它可能有点混乱,但它确实是有意义的。想一想,谢谢大家在这里的评论。所有这些答案都很有帮助。我仍然担心你能做到这一点,但至少你的评论似乎说明了我应该如何看待它。就像+运算符对不同类型有不同的影响一样,${w->wIndeed也有不同的影响。我仍然不完全确定那里发生了什么。${w->wIndeed。我仍然不完全确定那里发生了什么。
def x = 2
x << 2 //x == 8
"${ w -> w << 3}" //w == 3
def transform(List elements, Closure action) {                    
    def result = []
    elements.each {
        result << action(it)
    }
    result
}
def x = 2
assert x << 2 == 8
assert "${ w -> w << 3}" == '3'
def transform(List elements, Closure action) {                    
    def result = []
    elements.each {
        result << action(it)
    }
    result
}
class Lol {
    def leftShift(o) {
        println o
    }
}

new Lol() << 'string' //prints 'string'