Привет всем, следующий код не выполняется, код
class Invoice{
List items
Date date
}
class LineItem{
Product product
int count
int total(){
return product.dollar * count
}
}
class Product{
String name
def dollar
}
def ulcDate = new Date(107,0,1)
def ulc = new Product(name:'ULC', dollar:200)
def ve = new Product(name:'Visual Editor',dollar:500)
def invoices =[new Invoice(date:ulcDate, items: [new LineItem(count:5, product:ulc),new LineItem(count:2, product:ve)]), new Invoice(date:[107,1,1],items:[new LineItem(count:4,product:ve)])]
assert [200,500,400] == invoices.items*.total()
Это имя файла Test.groovy
, и когда я выполняю вот так groovy Test
я получаю такую ошибку:
Caught: groovy.lang.MissingMethodException: No signature of method: java.util.ArrayList.total() is applicable for argument types: () values: []
Possible solutions: tail(), getAt(groovy.lang.Range), getAt(java.util.Collection), getAt(int), getAt(java.lang.String), getAt(java.lang.String)
at In1.run(In1.groovy:20)
Даже если я определил метод total()
, он выдает ошибку?В чем причина?