我是Groovy的新手,只是让这个程序运行有些麻烦.我所要做的就是将一个列表的所有元素添加到另一个列表中,但我甚至无法访问方法中我想要的变量.
我环顾四周寻找答案,但似乎对于一个人的问题来说太过具体,或者对我对Groovy的有限理解太过技术性.任何帮助表示赞赏.
Groovy 2.4.5在IntelliJ IDEA中使用,如果这有所作为.这是我试图运行的代码:
class ListPractice implements Testable {
def mylist = [4,5,6]
/**
* Adds a set of elements to the mylist variable
*
* @paraelts The elements to be added
*/
def addToList(List elts) {
myList.each{
println "I: $it"
}
}
@Override
void testMe() {
addToList([7,8,9])
}
}
Run Code Online (Sandbox Code Playgroud)
但它会引发以下错误:
Caught: groovy.lang.MissingPropertyException: No such property: myList
for class: ListPractice
Possible solutions: mylist
groovy.lang.MissingPropertyException: No such property: myList for class: ListPractice
Possible solutions: mylist
at ListPractice.addToList(ListPractice.groovy:14)
at ListPractice$addToList.callCurrent(Unknown …Run Code Online (Sandbox Code Playgroud) groovy ×1