开发者

Evaluating a GROOVY expression while debugging

I'm trying to debug a simple groovy project in eclipse, code is as simple as this:

def list = [1, 2, 3, 4, 5]
println list.collect { it + 1 }

And it executes fine; only when I try to evaluate this part:

list.collect { it + 1 }

in the display view (or inspect it in the editor: shift+crl+i) I'm shot at with the following message:

list.collect { it + 1开发者_如何学编程 }
    Evaluation failed. Reason(s):
        org.codehaus.groovy.runtime.InvokerInvocationException (id=115)

Anyone ever had this issue, and knows how to fix it? Thanks a ton.

Using STS 2.5.2 (Eclipse 3.6.1r361), Groovy 1.7.8, jdk1.6.0_24; Groovy-Eclipse Plugin 2.1.2.xx.20110218

And btw, I think the problem didn't occur back when I was using sts 2.3.x (eclipse 3.5.x)


You cannot create closures in the display view. Instead, you will need to write this out in a for loop. Eg-

def newList = []
for (elt in list) {
  newList << elt++
}
print newList

This is a vm limitation since under the hood, a closure is represented by a class declaration. There is no easy way to inject a class generated by the display view into the running application.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜